project.urls
from django.contrib import admin
from django.conf.urls import include, url, patterns
from django.conf.urls.static import static
from django.conf import settings
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
admin.autodiscover()
urlpatterns = patterns('',
url(r'^$', include('app.urls', namespace = 'app')),
)+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += staticfiles_urlpatterns()
app.urls
urlpatterns = patterns('',
# ex: /polls/,
url(r'^', index.as_view(), name = 'index'),
url(r'^contact/', ContactMail.as_view(), name = 'contact'),
# url(r'^register/', register.as_view(), name = 'register'),
# url(r'^login/', login_user.as_view(), name = 'login'),
)+ static(settings.STATIC_URL,document_root = settings.STATIC_ROOT)
urlpatterns + = staticfiles_urlpatterns()
HTML
<a class="page-scroll" href="{% url 'app:contact' %}">Contact</a>
我收到错误:
Reverse for 'contact' with arguments '()' and keyword arguments '{}' not found. 1 pattern(s) tried: [u'$contact/']
知道为什么会这样吗?
提前致谢!
答案 0 :(得分:3)
您已通过以$结尾的正则表达式包含应用程序网址,因此不会包含任何内容。不要那样做。
url(r'^', include('app.urls', namespace = 'app')),
答案 1 :(得分:2)