我试图在我的模板中使用已命名的网址,但它不起作用。我已经尝试将模板中调用的网址名称更改为'progress'
,这是urls.py
中的另一个网址。它工作正常。但当我将其更改为UserSair
时,它就会崩溃。
我收到此错误:
NoReverseMatch at /
Reverse for 'UserSair' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
在这一行:
<a href="{% url "UserSair" %}" class="btn btn-default btn-flat">Sair</a>
这是我的urls.py
:
from django.conf.urls import patterns, include, url
from django.core.urlresolvers import reverse
from django.contrib.sitemaps import Sitemap, FlatPageSitemap
sitemaps = {
'site': Sitemap,
'flatpages': FlatPageSitemap,
}
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'quiz.views.home', name='home'),
# url(r'^quiz/', include('quiz.foo.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
####################
# quiz base url
url(r'^$', 'simulado.views.index'),
# quiz category list
url(r'^category/(?P<slug>[^\.]+)', 'simulado.views.view_category', name='view_quiz_category'),
#django social auth
url(r'', include('social_auth.urls')),
#notificacoes pagseguro
url(r'^notif$', 'simulado.views.notificacao', name = "notif"),
# cart
url(r'^carrinho$', 'simulado.views.carrinho'),
url(r'^buyItem$', 'simulado.views.buyItem', name = "buyItem"),
# obrigado, return from pagseguro
url(r'^obrigado$', 'simulado.views.obrigado'),
#sitemaps
url(r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap',{'sitemaps': sitemaps}, name='django.contrib.sitemaps.views.sitemap'),
# progress
url(r'^progress/$', 'simulado.views.progress', name = "progress"),
url(r'^progress$', 'simulado.views.progress', name = "progress"),
# logout
url(r'^UserSair/$', 'simulado.views.sair', name = "UserSair"),
url(r'^UserSair$', 'simulado.views.sair', name = "UserSair"),
# passes variable 'quiz_name' to quiz_take view
url(r'^(?P<quiz_name>[\w-]+)/$',
'simulado.views.quiz_take'), # quiz/
url(r'^(?P<quiz_name>[\w-]+)$/',
'simulado.views.quiz_take'), # quiz
url(r'^(?P<quiz_name>[\w-]+)/take/$',
'simulado.views.quiz_take'), # quiz/take/
url(r'^(?P<quiz_name>[\w-]+)take$',
'simulado.views.quiz_take'), # quiz/take
)
urlpatterns += patterns("",
url(r'^sitemap\.xml$',
'django.contrib.sitemaps.views.sitemap',
{'sitemaps': sitemaps}
),
)
这就是观点:
def sair(request):
return render(request, 'quiz_index.html')