I want to have a URL like these --
/chart/2012
/chart/2009
/chart/1996
...each #, is a year. So I added this line into my app's urls.py --
url(r'^chart/(?P<year>\d+)$',views.chart,name="chart"),
but it turns in a 404 when I go to the URL's. Shouldn't the \d+ capture the digits into the year variable?
(and yes, I do have a chart function defined in my views.py & it works when I don't try to use a variable with it)
UPDATE:
Here's the full urls.py --
from django.conf.urls import patterns,url
from musichart import views
urlpatterns = patterns('',
url(r'^$', views.index, name="index"),
url(r'^chart/(?P<year>\d+)$',views.chart,name="chart"),
)
Here's my views.py --
from django.shortcuts import render, get_object_or_404
from django.http import HttpResponseRedirect, HttpResponse
from django.template import RequestContext, loader #Context
from musichart.models import Station,Song,Album,Related,Artist
def index(request):
template = loader.get_template('chart/index.htm')
context = RequestContext(request, {
'title': "Here is the title",
'testvar': "blah blah blah testing 1 2 3",
'numero': 17,
})
return HttpResponse(template.render(context))
def chart(request, year):
template = loader.get_template('chart/chart.htm')
context = RequestContext(request, {
'title': "Here is the title",
'testvar': "blah blah blah testing 1 2 3",
'numero': 17,
})
return HttpResponse(template.render(context))
As you can see, it's bare bones at the moment and just sort of testing to make sure things go through before I go any further. And the 404 page says --
Using the URLconf defined in msite.urls, Django tried these URL patterns, in this order:
^admin/
^accounts/
^chart/ ^$ [name='index']
^chart/ ^chart/(?P<year>\d+)$ [name='chart']
^health/
The current URL, chart/2010, didn't match any of these.
chartfunction take ayearparameter?