我在网站的主页上收到此错误:
> 的NoReverseMatch反向退出'参数'()'和关键字参数' {}'未找到。尝试了0种模式:[]。
这是我的urls.py:
from django.conf import settings
from django.conf.urls.static import static
from django.conf.urls import url, include
from django.contrib import admin
from profiles import views as profiles_views
from contact import views as contact_views
from checkout import views as checkout_views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$', profiles_views.home, name='home'),
url(r'^about/$', profiles_views.about, name='about'),
url(r'^profile/$', profiles_views.userProfile, name='profile'),
url(r'^checkout/$', checkout_views.checkout, name='checkout'),
url(r'^contact/$', contact_views.contact, name='contact'),
url(r'^accounts/', include('allauth.urls')),
]
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root= settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root= settings.MEDIA_ROOT)
views.py:
from django.contrib.auth.decorators import login_required
from django.shortcuts import render
#Create your views here
def home(request):
context = {}
template = 'home.html'
return render(request,template,context)
def about(request):
context = {}
template = 'about.html'
return render(request,template,context)
@login_required
def userProfile(request):
user = request.user
context = {'user': user}
template = 'profile.html'
return render(request,template,context)
追溯:
File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\core\handlers \exception.py" in inner
39. response = get_response(request)
File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\core\handlers \base.py" in _get_response
187. response = self.process_exception_by_middleware(e, request)
File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\core\handlers\base.py" in _get_response
185. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\Adila\Documents\tryFOUR\src\profiles\views.py" in home
8. return render(request,template,context)
File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\shortcuts.py" in render
30. content = loader.render_to_string(template_name, context, request, using=using)
File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\template\loader.py" in render_to_string
68. return template.render(context, request)
File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\template\backends\django.py" in render
66. return self.template.render(context)
File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\template\base.py" in render
208. return self._render(context)
File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\template\base.py" in _render
199. return self.nodelist.render(context)
File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\template\base.py" in render
994. bit = node.render_annotated(context)
File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\template\base.py" in render_annotated
961. return self.render(context)
File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\template\loader_tags.py" in render
174. return compiled_parent._render(context)
File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\template\base.py" in _render
199. return self.nodelist.render(context)
File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\template\base.py" in render
994. bit = node.render_annotated(context)
File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\template\base.py" in render_annotated
961. return self.render(context)
File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\template\loader_tags.py" in render
210. return template.render(context)
File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\template\base.py" in render
210. return self._render(context)
File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\template\base.py" in _render
199. return self.nodelist.render(context)
File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\template\base.py" in render
994. bit = node.render_annotated(context)
File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\template\base.py" in render_annotated
961. return self.render(context)
File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\template\defaulttags.py" in render
447. url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app)
File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\urls\base.py" in reverse
91. return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))
File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\urls\resolvers.py" in _reverse_with_prefix
389. (lookup_view_s, args, kwargs, len(patterns), patterns)
Exception Type: NoReverseMatch at /
Exception Value: Reverse for 'logout' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
我查看了其他帖子并且找不到任何有帮助的帖子,我刚加入这个项目,所以我不知道原来的程序员在这里尝试做什么。
答案 0 :(得分:0)
您使用的home.html
中的某个地方
{% url 'logout' %}
但您的网址中没有“退出”
我想你想要从allauth.urls
{% url 'account_logout' %}
答案 1 :(得分:0)
更改您的主页'或者您使用logout
网址的任何地方,将其更改为
{% url 'account_logout' %}