我需要添加一个功能,任何人都可以在我的图像应用程序中添加新图像。
所以我在模板中给出了一个Add Image应用程序链接。默认情况下,此链接应在models.py中调用Photo模型的Add方法,即
class Image(models.Model):
title = models.CharField(max_length=60)
我的html文件看起来像这样
<h3><a href="{% url photoapp.views.main %}">PhotoApp</a></h3>
{% if user.is_staff %}
<a href='{% url admin:index %}'>Admin</a>
<a href="{% url admin:photoapp.add_image %}">Add Image</a>
<a href="{% url photoapp.views.search %}">Search</a>
{% endif %}
这里告诉我
Caught NoReverseMatch while rendering: Reverse for 'photoapp.add_image' with arguments '()' and keyword arguments '{}' not found.
我的项目名称是包含photoapp的照片
photo
photoapp
models.py
views.py
templates
photo
list.html
admin
base_site.html
settings.py
urls.py
请让我知道如何从.html文件中调用默认添加模型功能
修改
添加了url.py
urlpatterns = patterns('',
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
url(r'^(\d+)/$', photo.photoapp.views.album),
url(r'^(\d+)/(full|thumbnails|edit)/$', photo.photoapp.views.album),
url(r'^update/$', photo.photoapp.views.update),
url(r'^search/$', photo.photoapp.views.search),
url(r'^image/(\d+)/$', photo.photoapp.views.image),
url(r'', photo.photoapp.views.main),
)
if settings.DEBUG:
urlpatterns += patterns('django.views.static',
(r'media/(?P<path>.*)$', 'serve', {'document_root': settings.MEDIA_ROOT}),
)
答案 0 :(得分:4)
您的app_name是photoapp,型号名称是Image。
要在模板中使用admin的Add Image应用程序链接,请编写代码
{% url admin:photoapp_image_add %}
提供网址 - / photoapp / image / add /