0
votes

Using the URLconf defined in learnpy.urls, Django tried these URL patterns, in this order: [name='index'] admin/ The current path, Envs/python-projects/learnpy/static/styles/bootstrap4/bootstrap.min.css, didn't match any of these.

Above error occuring in create django static page Please help me

See belowe image:

enter image description here

Myapp url: travello/urls.py

from django.urls import path

from . import views

urlpatterns = [ path('',views.index, name='index')]

Main app urls: learnpy/urls.py

from django.contrib import admin

from django.urls import path, include

urlpatterns = [
path('', include('travello.urls')),

path('admin/', admin.site.urls),

]

Myapp view file: travello/views.py

from django.shortcuts import render

def index(request):

return render(request, 'index.html')

In index.html

{% load static %}

set above code in my index.html file

3

3 Answers

1
votes

I think you have not added the static URLs path to your project.

  1. Make sure that django.contrib.staticfiles is included in your INSTALLED_APPS.

  2. In your settings file, define STATIC_URL, for example:

    STATIC_URL = '/static/'

  3. In your templates, use the static template tag to build the URL for the given relative path using the configured STATICFILES_STORAGE.

    {% load static %}
    <img src="{% static "my_app/example.jpg" %}" alt="My image">
    
  4. Also you need to add static directory in your settings file


    STATICFILES_DIRS = [
        os.path.join(BASE_DIR, 'static')
    ]

for further reading please check the docs here https://docs.djangoproject.com/en/3.0/howto/static-files/#configuring-static-files

0
votes

Required Static file Dir in Django Setting file. then u resolve this error.

please follow this link for more understanding.

https://docs.djangoproject.com/en/3.0/howto/static-files/

 STATIC_URL = '/static/'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static')
]
0
votes

Are you using 'django-bootstrap4'? If so, you should add 'bootstrap4' to 'INSTALLED_APPS' in your project's 'settings.py' file.