Django: “Reverse not found”

Do you have a view named viewPlan with which you do something like this in a template: {% url viewPlan %} or something like this in a view: reverse(‘viewPlan’) If you do that and you do not have a line that looks like this: url(r’^whatever/url/$’, ‘dev_env.profiles.views.viewPlan’, name=”viewPlan”), …in your url configuration I would imagine that’s … Read more

Django. TemplateDoesNotExist in case of a custom widget

If you want to use a custom widget template stored somewhere under your “TEMPLATES” directory of your project then follow these steps: a) Use the TEMPLATES settings that you have provided in your question b) Set the FORM_RENDERER as following in the settings.py FORM_RENDERER = ‘django.forms.renderers.TemplatesSetting’ c) Add the app “django.forms” to the ‘INSTALLED_APPS‘ list … Read more

What are the steps to make a ModelForm work with a ManyToMany relationship with an intermediary model in Django?

If you use the save method right now, Django will try to save using the manager (which Django doesn’t allow). Unfortunately, the behavior you want is a little bit trickier than what ModelForm does by default. What you need to do is create a formset. First of all, you will need to change the options … Read more

how to embed standalone bokeh graphs into django templates

Using the Embedding Bokeh Plots documentation example as suggested by Fabio Pliger, one can do this in Django: in the views.py file, we put: from django.shortcuts import render from bokeh.plotting import figure from bokeh.resources import CDN from bokeh.embed import components def simple_chart(request): plot = figure() plot.circle([1,2], [3,4]) script, div = components(plot, CDN) return render(request, “simple_chart.html”, … Read more

Setting up Mimetype when using TemplateView in Django

For Django >= 1.5 TemplateView accepts a content_type argument. Coping example from @Meilo urlpatterns = patterns(”, url(r’^test\.txt$’, TemplateView.as_view(template_name=”staticpages/test.html”, content_type=”text/plain”)), For Django < 1.5 I think that just calling TemplateView.as_view() is not posible but maybe i missed it (from the source), but you can do your own class class TextTemplateView(TemplateView): def render_to_response(self, context, **response_kwargs): response_kwargs[‘content_type’] = … Read more

django – what goes into the form action parameter when view requires a parameter?

If you want to explicitly set the action, assuming you have a variable username in your template, <form name=”form” method=”post” action=”{% url myview.views username %}”> or you could assign a name for the url in your urls.py so you could reference it like this: # urls.py urlpatterns += patterns(‘myview.views’, url(r’^(?P<user>\w+)/’, ‘myview’, name=”myurl”), # I can’t … Read more

File not found.