I have URLs like http://example.com/depict?smiles=CO&width=200&height=200 (and with a few other optional arguments)
My urls.py contains:
urlpatterns = patterns('', (r'^$', 'cansmi.index'), (r'^cansmi$', 'cansmi.cansmi'), url(r'^depict$', cyclops.django.depict, name="cyclops-depict"),
I can go to this URL and get the created PNG 200x200, so I know this part works.
In my template from the answer "cansmi.cansmi" I want to create a URL for the named template "cyclops-pictict" taking into account some request parameters. I thought I could do
{% url cyclops-pictict smiles = input_smiles width = 200 height = 200%}
where "input_smiles" is the input to the template by submitting the form. In this case, this is the string "CO", and I thought I would create a URL similar to the one at the top.
This template does not work with TemplateSyntaxError:
Showing exceptions when rendering: Reverse for 'cyclops-pictict' with arguments' () 'and keyword arguments' {' smiles': u'CO ',' height ': 200,' width ': 200}' not found.
This is a fairly common error message both here and in StackOverflow and elsewhere. In each case, I found that people used them with parameters in the URL regular expression URL, which does not match me where the parameters are included in the request.
This means that I am doing it wrong. How do I do it right? That is, I want to build the full URL, including the path and request parameters, using something in the template.
For reference,
% python manage.py shell Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) >>> from django.core.urlresolvers import reverse >>> reverse("cyclops-depict", kwargs=dict()) '/depict' >>> reverse("cyclops-depict", kwargs=dict(smiles="CO")) Traceback (most recent call last): File "<console>", line 1, in <module> File "/Library/Python/2.6/site-packages/django/core/urlresolvers.py", line 356, in reverse *args, **kwargs))) File "/Library/Python/2.6/site-packages/django/core/urlresolvers.py", line 302, in reverse "arguments '%s' not found." % (lookup_view_s, args, kwargs)) NoReverseMatch: Reverse for 'cyclops-depict' with arguments '()' and keyword arguments '{'smiles': 'CO'}' not found.