0

Cannot make url with query strings in django template: Here is example:

<a href="{% url getFormMetaData %}?code=RHJ6YXZh">Form</a>

and urls.py file looks like this:

url(r'^main/getFormMetaData/$', views.getFormMetaData, name='getFormMetaData'),
5
  • Alo i tried in url tag "views.getFormMetaData" .... Commented Sep 11, 2013 at 14:44
  • what is the problem you are facing? Commented Sep 11, 2013 at 14:46
  • 'url' requires a non-empty first argument. The syntax changed in Django 1.5, see the docs. Commented Sep 11, 2013 at 14:46
  • 1
    And did you see the docs? They explain it completely. Plus, this has nothing to do with the query string. Commented Sep 11, 2013 at 14:48
  • Yes i saw the docs but no success for now... Commented Sep 11, 2013 at 14:51

2 Answers 2

1

You need to put single quotes around getFormMetaData. Not using quotes was acceptable in previous version of Django, but that has now been deprecated.

Thus, your code should be:

<a href="{% url 'getFormMetaData' %}?code=RHJ6YXZh">Form</a>

Reference: https://docs.djangoproject.com/en/dev/ref/templates/builtins/#url

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

7 Comments

Hm now i'm getting Reverse for 'getFormMetaData' with arguments '()' and keyword arguments '{}' not found.
Some Django projects use a "multi-site" directory structure. Typically there is a folder that contains top level URLs, settings, and wsgi script contents. Are you properly including your site's URLs in that top level URL locator file?
Hmm, in that case, could you double check that you are referring to the correct view? If your view function is contained directly in views.py then views.getFormMetaData is correct. But, if it's contained in a file that is within a views directory then you will need to say views.some_filename.getFormMetaData.
Function is directly in views.py, i will check again does link works
Make sure that your view signature expects no parameters (except for the standard request that is passed in. Thus, your view should read: def getFormMetaData(request):. If there are more arguments to the function then you must pass that as a parameter in the URL template call.
|
0

I must answer my own question...

Something really not good here...

in that urls.py file i have something like this:

url(r'^main/$', views.main, name='main'),
url(r'^main/getFormMetaData/$', views.getFormMetaData, name='getFormMetaData'),

These url tags i have in main.html. I can access to main.html like this:

http://localhost:9000/TestProjekat/main/

Now, how to pass an one or two arguments in getFormMetaData from main.html.. How to wrote url tags?

3 Comments

Per the Django documentation: {% url 'namedURL' v1 v2 %}. Alternatively, you may name the arguments: {% url 'namedURL' arg1=v1 arg2=v2 %}.
I saw that but dont know how to use it :)
AAAAA solved! in top level urls.py i have namespace. I removed it and now works! :) Thanks for answers!

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.