[英]Url in template from site-package
i'm building my first Django app so i'm know i'm missing a lot of things, but i installed a gallery for my site and is inside site-packages, i set the url inside urls.py and it looks like this :我正在构建我的第一个 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)
I can perfectly access the gallery and its functionalities if i write the url in the browser, but i cannot reference the gallery Url inside my template like the other Urls using {% url 'gallery' %}, i keep getting this error :如果我在浏览器中写入 url,我可以完美地访问图库及其功能,但是我无法像使用 {% url 'gallery' %} 的其他 Urls 一样在模板中引用图库 Url,我不断收到此错误:
Reverse for 'gallery' not found.未找到“画廊”的反向。 'gallery' is not a valid view function or pattern name. 'gallery' 不是有效的视图函数或模式名称。
Also heres the gallery url:还有这里的画廊网址:
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')
]
Thanks!谢谢!
app_name = 'gallery'
urlpatterns = [
path('admin/', admin.site.urls),
path('gallery/', include('gallery.urls')),
path('home/',Home,name='home'),
path('contacto/',Contacto,name='contacto')
]
Change it as shown above and call gallery:album_list
for album list, and follow same pattern for others如上所示更改它并调用gallery:album_list
为专辑列表,并为其他人遵循相同的模式
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.