简体   繁体   English

如何更改Django框架中的URL

[英]How do I change the URL in Django framework

I'm trying to make a website using Django and I got some error message like this我正在尝试使用 Django 创建一个网站,但我收到了这样的错误消息

Request URL:    http://127.0.0.1:8000/store.html

Using the URLconf defined in greatkart.urls, Django tried these URL patterns, in this order:

    admin/
    [name='home']
    store/
    ^media/(?P<path>.*)$

The current path, store.html, didn't match any of these.

The problem is when I tried to click button it always print./store.html not the./store it's my html code for the button问题是当我尝试单击按钮时它总是打印./store.html 而不是./store 这是我的按钮代码 html

<a href="./store.html" class="btn btn-outline-primary float-right">See all</a>

And this is my Django for urls.py (main)这是我的 Django 的 urls.py(主要)

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', views.home, name='home'),
    path('store/', include("store.urls"))
] + static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)

This urls.py(store)这个 urls.py(store)

urlpatterns = [
    path('', views.store, name='store'),
    path('<slug:category_slug>/', views.store, name='product_by_category'),
]

views.py视图.py

def store(request, category_slug = None):
    return render(request, 'store/store.html', context)

Anyone have some idea?有人知道吗? I want to fix it without changing the HTML code because I've tried it and when I click on the buttons twice that make some error because the URL print the./store twice我想在不更改 HTML 代码的情况下修复它,因为我已经尝试过了,当我点击按钮两次时出现一些错误,因为 URL 打印了./store 两次

Here the url should be absolute(starting with a / excluding you localhost address) and should not include .html .这里的 url 应该是绝对的(以/开头,不包括你的本地主机地址)并且不应该包括.html So Your Url should be: /store and the anchor tag should be: <a href="/store" class="btn btn-outline-primary float-right">See all</a>所以你的 Url 应该是: /store锚标签应该是: <a href="/store" class="btn btn-outline-primary float-right">See all</a>

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

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