繁体   English   中英

来自站点包的模板中的 URL

[英]Url in template from site-package

我正在构建我的第一个 Django 应用程序,所以我知道我错过了很多东西,但是我为我的网站安装了一个画廊并且在网站包中,我在 urls.py 中设置了 url,它看起来像这样:

from django.contrib import admin
from django.urls import path,include
from django.conf import settings
from django.conf.urls.static import static
from contacto.views import Home,Contacto



urlpatterns = [
    path('admin/', admin.site.urls),
    path('gallery/', include('gallery.urls'),name='gallery'),
    path('home/',Home,name='home'),
    path('contacto/',Contacto,name='contacto')

]
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

如果我在浏览器中写入 url,我可以完美地访问图库及其功能,但是我无法像使用 {% url 'gallery' %} 的其他 Urls 一样在模板中引用图库 Url,我不断收到此错误:

未找到“画廊”的反向。 'gallery' 不是有效的视图函数或模式名称。

还有这里的画廊网址:

from django.urls import path

from gallery.views import ImageView, ImageList, AlbumView, AlbumList, ImageCreate


app_name = 'gallery'
urlpatterns = [
    path('', AlbumList.as_view(), name='album_list'),
    path('images/', ImageList.as_view(), name='image_list'),
    path('image/<int:pk>/<slug>', ImageView.as_view(), name='image_detail'),
    path('upload/', ImageCreate.as_view(), name='image_upload'),
    path('album/<int:pk>/<slug>/', AlbumView.as_view(), name='album_detail'),
    path('album/<int:apk>/<int:pk>/<slug>', ImageView.as_view(), name='album_image_detail')
]

谢谢!

app_name = 'gallery'
urlpatterns = [
    path('admin/', admin.site.urls),
    path('gallery/', include('gallery.urls')),
    path('home/',Home,name='home'),
    path('contacto/',Contacto,name='contacto')

]

如上所示更改它并调用gallery:album_list为专辑列表,并为其他人遵循相同的模式

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM