In urls.py:
(r'^bbb/id(?P<user_id>[0-9]+)/$', 'django.views.generic.simple.direct_to_template,
{'template': 'some.html', 'extra_context': {'user_id': user_id}}),
In some.html: {{ user_id }}
But there is an error: name 'user_id' is not defined (in urls.py)
So, how to declare that variable in urls.py and send it directly to ‘some.html’???
Thanks.
You don’t need to put it in
extra_context. It’s already captured in the URL, so is present in theparamsdictionary in the template:{{ params.user_id }}.See the documentation – and also note that these old function-based generic views are deprecated, and you should be using the class-based TemplateView.