我需要添加一个功能,任何人都可以在我的图像应用程序中添加新图像。
所以我在模板中给出了一个添加图像应用程序链接。默认情况下,此链接应在 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}),
)