djangosnippets.org: Latest snippets posted by orblivionhttps://djangosnippets.org/users/orblivion/2010-10-28T16:33:15.940479-05:00orblivionAllow any view (probably a generic view) to accept POST variables into extra_context
2010-10-28T16:33:15.940479-05:00orblivionhttps://djangosnippets.org/snippets/2246/<p>Supposing you wanted to use a generic view, but you wanted to pass something over POST to show up in the resultant template. Perhaps you're creating a new object, and you want to pre-populate some hidden fields.
</p>
<p><code>urlpatterns = patterns('django.views.generic.create_update',
url(r'^obj/new$', view_post_vars_to_context(create_object), {'form_class': ThingForm, 'template_name': 'thing/new_thing.html', 'post_vars_to_context':{'obj_id':'objID'}, extra_context: {:this":"that"}}),
) …</code></p>
Freely redistributableAllow any view (probably a generic view) to accept captured URL variables into extra_context.
2010-10-28T15:28:54.432681-05:00orblivionhttps://djangosnippets.org/snippets/2245/<p>If your URL pattern looks like:</p>
<p><code>urlpatterns = patterns('django.views.generic.create_update',
url(r'^obj/(?P<obj_id>\d+)/new_thing$', create_object, {'form_class': ThingForm, 'template_name': 'thing/new_thing.html', extra_context: {:this":"that"}),
)</code></p>
<p>You will receive an error, because the create_update view doesn't have a parameter called "obj_id". Supposing you want that variable in the URL, and furthermore let's say you wanted to do something …</p>
Freely redistributable