I have a template for an about page which refuses to show. I'm probably doing something silly but I can't work out why and it's driving me insane!
part of views.py:
# About view
def about(request):
return render(request, 'blog/about.html')
urls.py:
from django.conf.urls import patterns, include, url
from django.contrib import admin
from blog.views import post as blog_post
from blog.views import profile as blog_profile
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^$', 'blog.views.index'),
url(r'^about/$', 'blog.views.about'),
url(r'^profiles/$', 'blog.views.profile_index'),
url(r'^profiles/(?P<profile_url>[\w\-]+)/$', blog_profile, name = 'blog_profile'),
url(r'^(?P<category>[\w\-]+)/$', 'blog.views.categoryIndex'),
url(r'^(?P<category>[\w\-]+)/(?P<slug>[\w\-]+)/$', blog_post, name = 'blog_post')
)
the about template (not including the base.html):
{% extends 'base.html' %}
{% block title %} About {% endblock %}
{% block content %}
<h1>About</h1>
{% endblock %}
Using Django 1.6.5
Tried to navigate to mysite.com/about/
Template hierachy:
templates
base.html
blog
about.html
....
I've figured out the problem, the following url was being matched with the about page instead:
url(r'^(?P<category>[\w\-]+)/$', 'blog.views.categoryIndex'),
Removing this solves the issue and displays the about page. This page explains about url ordering http://www.webforefront.com/django/regexpdjangourls.html
Because my about url was listed before the conflicting one, it was skipped.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments