来自另一个应用程序的 django 模板 url [英] django template url from another app
本文介绍了来自另一个应用程序的 django 模板 url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须错过一些愚蠢的东西.我在模板中有一个 {% url %},其中的操作来自另一个应用程序.它不起作用,但我不知道使用其他应用的视图函数是否有什么不同,或者我只是在做一些愚蠢的事情.
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
call/template/call/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: []
推荐答案
当在来自不同应用程序的 URL 上调用 reverse()
时,你应该使用它的命名空间"版本,就像这样:
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' %}
这篇关于来自另一个应用程序的 django 模板 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文