0

I've some url that I want to render a template without creating a view for each one, but inside I need a form with the csrf tag, so when the user post the form I get no csrf token becouse the template have no RequestContext render on it.

How can I render templates declare in url and use csrf without creating a view for each one

My urls.py path('path/', TemplateView.as_view(template_name='template.html')),

The error: CSRF token missing or incorrect. UserWarning: A {% csrf_token %} was used in a template, but the context did not provide the value. This is usually caused by not using RequestContext. "A {% csrf_token %} was used in a template, but the context "

Mariano DAngelo
  • 920
  • 5
  • 18
  • 39
  • I don't think the view is causing the issue with the ```csrf_token```, make sure you have the context processor ```'django.core.context_processors.csrf'``` activated. Also if you want to add context to your view you can do: ```path('path/', TemplateView.as_view(template_name='template.html', extra_context={'some_context': context })),``` – p14z Apr 14 '19 at 16:24
  • TemplateView already uses a RequestContext. – Daniel Roseman Apr 14 '19 at 17:40

0 Answers0