10

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: []
6
  • Is the file intentionally named url.py or is it a typo?
    – alecxe
    Nov 8, 2014 at 2:38
  • it was a typo...fixed now
    – brechmos
    Nov 8, 2014 at 2:44
  • 2
    What if you use a namespaced version {% url 'picture:upload_image' %} instead?
    – alecxe
    Nov 8, 2014 at 2:48
  • I tried action="{% url 'picture:upload_image' %}" and url(r'^upload_image/$', upload_image, namespace='picture', name='upload_image'), but says picture is not a registered namespace. (I haven't used namespaces before.)
    – brechmos
    Nov 8, 2014 at 3:00
  • oh, or is the namespace go in the project urls.py list (and not in picture/urls.py)
    – brechmos
    Nov 8, 2014 at 3:01

1 Answer 1

18

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' %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.