0

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.

2 Answers 2

6

You don't need to put it in extra_context. It's already captured in the URL, so is present in the params dictionary 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.

Sign up to request clarification or add additional context in comments.

Comments

0

The variable really isn't declared in that python code. :) You do not need to set this variable in the view context. The view will receive named matches as **kwargs.

1 Comment

But as you see I use generic views... How send it directly to template?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.