2014-11-08 65 views
3

我必须错过一些愚蠢的东西。我有一个模板中的{%url%},其中的操作来自另一个应用程序。它不工作,但我不知道如果从其他应用程序使用视图功能有什么不同,或者我只是在做一些愚蠢的事情。从另一个应用程序django模板url

呼叫/模板/电话/ file.html

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

图片/ urls.py

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

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

图片/ view.py

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

所有我曾经得到的是:

NoReverseMatch at /call/4/ 

Reverse for 'upload_image' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: [] 
+0

该文件是故意命名为'url.py'还是它是一个错字? – alecxe 2014-11-08 02:38:59

+0

这是一个错字...现在修复了 – brechmos 2014-11-08 02:44:37

+1

如果您使用名称空间版本“{%url”图片:upload_image'%}'而不是? – alecxe 2014-11-08 02:48:00

回答

2

当调用对来自不同应用程序的URL reverse(),你应该使用它的“命名空间”的版本,像这样:

{% url 'app_name:app_url' %} 

在特定情况下,转化为:

{% url 'picture:upload_image' %} 
相关问题