0

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 Answers 3

2

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

Sign up to request clarification or add additional context in comments.

15 Comments

I also set this two think
yes STATIC_ROOT = os.path.join(BASE_DIR, 'assets')
{% load static %} <!DOCTYPE html> <html lang="en"> <head> <title>Travello</title> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="description" content="Travello template project"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="{% static '/styles/bootstrap4/bootstrap.min.css' %}" type="text/css"> This code for index.html
I follow this tutorial #10 and #11 the same as creating code but still not working
|
0

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')
]

1 Comment

I also set this in settings.py file
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.