I’ve a django website set in French in the settings file.
In my template, I’ve the following entry <a href="/{{ year }}/{{ month|date:"b" }}/">{{ month|date:"F" }}</a>.
In my URLconf, I have the entry url(r'^(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{1,2})/$',MonthArchivePostView.as_view())
The problem is that in the template, the date generated is in French (for example, for February, I’ve got <a href="/2012/fév/">Février</a>) but the url expects the English version (/2012/feb/).
I don’t mind having the dates in the url in English or in French, I just need to have the same generated in with the template and expected in the URLconf file.
Thank you
Update quick-fix-not-really-a-solution : use the m format everywhere instead of b to have /02/ instead of /feb/
So in the urls.py
url(r'^(?P<year>\d{4})/(?P<month>\d{1,2})/$',
MonthArchivePostView.as_view()
),
and in the generic views
class MonthArchivePostView(dates.MonthArchiveView):
model = Post
month_format = '%m'
date_field = 'publish'
As @jkbr already said, unlocalize should do the job.
Beside of that, have you ever been thinking about adding a function
'get_absolute_url(self)'in the model definition of your entry model, instead of defining the url in the template?It would be better to keep separated content definition (model) from content presentation (template).
Also it could help you in solve your problem.
Try adding a function similar to this one at the end of your entry model:
This should work (if I’ve understood it right, it’s something about displaying data instead of parsing it, as explained in Format localization section of Django documentation.
Then in your template you could do something like: