Reputation: 11
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:
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
Upvotes: 0
Views: 1248
Reputation: 29
Are you using 'django-bootstrap4'? If so, you should add 'bootstrap4' to 'INSTALLED_APPS' in your project's 'settings.py' file.
Upvotes: 0
Reputation: 931
I think you have not added the static URLs path to your project.
Make sure that django.contrib.staticfiles is included in your INSTALLED_APPS.
In your settings file, define STATIC_URL, for example:
STATIC_URL = '/static/'
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">
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
Upvotes: 2
Reputation: 68
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')
]
Upvotes: 0