Home > Mobile >  How do I change the URL in Django framework
How do I change the URL in Django framework

Time:10-03

I'm trying to make a website using Django and I got some error message like this

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

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

And this is my Django for urls.py (main)

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)

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

views.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

CodePudding user response:

Here the url should be absolute(starting with a / excluding you localhost address) and should not include .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>

  • Related