Search code examples
pythondjangourlslug

Django URL trails other file URLs


I'm building a website on Django. Here is the problem :

url.py : 
    url(r'^product/(?P<slug>[-_\w]+)/$', ProductView.as_view(), name='product'),

This URL calls product/product-slug successfully, but it affects other files' urls. Error message is :

"GET /product/lenovo-tv/static/css/bootstrap.min.css HTTP/1.1" 404 4862

What am I missing? base.html :

<link href="static/css/bootstrap.min.css" rel="stylesheet"/>
<link href="static/css/font-awesome.min.css" rel="stylesheet">
<link href="static/css/custom-styles.css" rel="stylesheet">

Solution

  • {% load static %}
    <link href="{% static 'css/bootstrap.min.css' %}" rel="stylesheet"/>
    <link href="{% static 'css/font-awesome.min.css' %}" rel="stylesheet">
    <link href="{% static 'css/custom-styles.css' %}" rel="stylesheet">
    

    in your html use the static files like this for css and js