Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django template url from another app

I have to be missing something silly. I have a {% url %} in a template where the action is from another app. It isn't working but I have no clue if there is something different about using view functions from other apps or if I am just doing something silly.

call/template/call/file.html

    <form action="{% url 'upload_image' %}"></form>

picture/urls.py

from .views import PictureList, PictureCreate, PictureDetail, PictureUpdate, PictureDelete, upload_image

...
url(r'^upload_image/$', upload_image, name='upload_image'),
...

picture/view.py

def upload_image( request ):
    print 'IN IMAGE UPLOAD'
    print request

All I ever get is:

NoReverseMatch at /call/4/

Reverse for 'upload_image' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
like image 422
brechmos Avatar asked Nov 08 '14 02:11

brechmos


People also ask

What does form {% URL %} do?

{% url 'contact-form' %} is a way to add a link to another one of your pages in the template. url tells the template to look in the URLs.py file. The thing in the quotes to the right, in this case contact-form , tells the template to look for something with name=contact-form .

How do I change the default URL in Django?

Set up app folder's urls.py and html files In the same directory, you should have a file named views.py. We will create a function called index which is what makes the http request for our website to be loaded. Now, we've set it up such that http://127.0.0.1:8000/homepage will render the HTML template index.


1 Answers

When calling reverse() on an URL that comes from a different application, you should use its "namespaced" version, like so:

{% url 'app_name:app_url' %}

In your specific case, that translates to:

{% url 'picture:upload_image' %}
like image 132
Andrew Schuster Avatar answered Sep 18 '22 13:09

Andrew Schuster