Reputation: 660
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>
I get the error:
Reverse for 'contact' with arguments '()' and keyword arguments '{}' not found. 1 pattern(s) tried: [u'$contact/']
Any idea why this is happening?
Thanks in advance!
Upvotes: 2
Views: 1307
Reputation: 9408
Including your app urls as
url(r'^$', include('app.urls', namespace = 'app')),
means that the only url you will get a match for is www.domainname.com/
because you're telling django that the url must begin with ''
, contain no characters and end in ''
, so in your app's urls the only url that matches that is the index
view.
If you want you app urls to be served starting at /
, your urls should be imported at
url(r'^', include('app.urls', namespace = 'app')),
For example, if you wanted your app urls to start at /app/
, like /app/contact/
you would do
url(r'^app/', include('app.urls', namespace = 'app')),
Check the django docs on this for more details.
Upvotes: 2
Reputation: 599490
You've included the app urls via a regex that ends in $, so nothing included will ever match. Don't do that.
url(r'^', include('app.urls', namespace = 'app')),
Upvotes: 3