K
K
kicherov_maxim2019-04-18 12:39:32
Django
kicherov_maxim, 2019-04-18 12:39:32

How to correctly write urlpatterns in django?

I want to receive get parameter in url

urlpatterns = [
    url(r'^$', views.index, name='index'),
    url(r'item', views.item, name='item'),
    url(r'^category/(?P<category>\w{0,50})/$', views.category,),
]

http://localhost:8000/category/name
the problem is that the static is broken, which is connected like this
<script src="./static/js/jquery-1.11.3.min.js"></script>

but requests go to
http://localhost:8000/category/название/static/js/jquery-1.11.3.min.js

Answer the question

In order to leave comments, you need to log in

1 answer(s)
7
776166, 2019-04-18
@kicherov_maxim

So static is not connected ideologically and especially in the way you did it.
"./"means that you are starting from the current location, which is completely wrong in general.
Need like this:

{% load static %}
<script src="{% static "js/jquery-1.11.3.min.js" %}"></script>

https://docs.djangoproject.com/en/2.2/howto/static...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question