我是安装了django 1.11.5的新手。这是来自macador app project的教程。我已经在项目主模板中创建了视图。我的登录和注销无效。当我运行runserver命令时,我收到以下错误。
执行系统检查......
Unhandled exception in thread started by <function wrapper at 0x7f087adf5aa0>
Traceback (most recent call last):
File "/root/Desktop/bookmarksmanager/myenv/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "/root/Desktop/bookmarksmanager/myenv/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 125, in inner_run
self.check(display_num_errors=True)
File "/root/Desktop/bookmarksmanager/myenv/local/lib/python2.7/site-packages/django/core/management/base.py", line 359, in check
include_deployment_checks=include_deployment_checks,
File "/root/Desktop/bookmarksmanager/myenv/local/lib/python2.7/site-packages/django/core/management/base.py", line 346, in _run_checks
return checks.run_checks(**kwargs)
File "/root/Desktop/bookmarksmanager/myenv/local/lib/python2.7/site-packages/django/core/checks/registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "/root/Desktop/bookmarksmanager/myenv/local/lib/python2.7/site-packages/django/core/checks/urls.py", line 16, in check_url_config
return check_resolver(resolver)
File "/root/Desktop/bookmarksmanager/myenv/local/lib/python2.7/site-packages/django/core/checks/urls.py", line 26, in check_resolver
return check_method()
File "/root/Desktop/bookmarksmanager/myenv/local/lib/python2.7/site-packages/django/urls/resolvers.py", line 254, in check
for pattern in self.url_patterns:
File "/root/Desktop/bookmarksmanager/myenv/local/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/root/Desktop/bookmarksmanager/myenv/local/lib/python2.7/site-packages/django/urls/resolvers.py", line 405, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/root/Desktop/bookmarksmanager/myenv/local/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/root/Desktop/bookmarksmanager/myenv/local/lib/python2.7/site-packages/django/urls/resolvers.py", line 398, in urlconf_module
return import_module(self.urlconf_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/root/Desktop/bookmarksmanager/myenv/src/mysite/urls.py", line 27, in <module>
name='mysite_login'),
File "/root/Desktop/bookmarksmanager/myenv/local/lib/python2.7/site-packages/django/conf/urls/__init__.py", line 85, in url
raise TypeError('view must be a callable or a list/tuple in the case of include().')
TypeError: view must be a callable or a list/tuple in the case of include().
来自模板:
{% extends "base.html" %}
{% load crispy_forms_tags %}
{% block title %}Login{% endblock %}
{% block toggle_login %}{% endblock %}
{% block heading %}
<h2>Login</h2>
{% endblock %}
{% block content %}
<form action="{% url "mysite_login" %}" method="post" accept- charset="utf-8">
{{ form|crispy }}
{% csrf_token %}
<input type="hidden" name="next" value="{{ next }}">
<input class="btn btn-default" type="submit" value="Login">
</form>
{% endblock %}
mysite.urls:
from django.conf.urls import url, include
from django.contrib import admin
from django.core.urlresolvers import reverse_lazy
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^bookmarksapp/',include('bookmarksapp.urls')),
url(r'^login/$', 'django.contrib.auth.views.login', {'template_name': 'login.html'},
name='mysite_login'),
url(r'^logout/$', 'django.contrib.auth.views.logout',
{'next_page': reverse_lazy('bookmarksapp_bookmark_list')}, name='mysite_logout'),
settings.py
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
LOGIN_URL = 'mysite_login'
LOGOUT_URL = 'mysite_logout'
答案 0 :(得分:1)
更新您的mysites.urls
,如下所示。
from django.conf.urls import url, include
from django.contrib import admin
from django.core.urlresolvers import reverse_lazy
from django.contrib.auth.views import login, logout
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^bookmarksapp/',include('bookmarksapp.urls')),
url(r'^login/$', login, {'template_name': 'login.html'},
name='mysite_login'),
url(r'^logout/$', logout,
{'next_page': reverse_lazy('bookmarksapp_bookmark_list')}, name='mysite_logout'),
因为错误说你的观点必须是可以调用的。
答案 1 :(得分:0)
我认为bookmarksapp.urls文件中存在一些错误。你可以发布它的内容吗? 另外,修改settings.py -
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static')
]
LOGIN_URL = 'mysite_login'
LOGOUT_URL = 'mysite_logout'
LOGIN_REDIRECT_URL = 'bookmarksapp_bookmark_list'