静态文件未载入django

0x6upsns  于 2022-12-20  发布在  Go
关注(0)|答案(1)|浏览(115)

我试图为我的应用创建一个主页,但添加STATIC_ROOTSTATICFILES_DIR后,我的页面一直在加载。它在我的终端中显示来自('127.0.0.1',49634)的管道中断。这是我的home.html
This is my settings.py

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = 'static/'
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')

this is my urls.py

if settings.DEBUG:
    urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
icnyk63a

icnyk63a1#

# -------- handle Static Files In dajngo --------
   
   # Steps:
       # 1 - Create (static) folder in Root Directory of Project
       # 2 - Paste Your Static Files Folder in (static) Folder (js,css,images...etc)
       # 3 - Now Do Setting in (setting.py)
              STATIC_URL = '/static/'
   
       STATICFILES_DIRS = [os.path.join(BASE_DIR,'static')]

           #-------- OR ----------

       STATICFILES_DIRS = [BASE_DIR / 'static']

       # 4 - add {% load static %} tag on top of html page
       # 5 - Now use ({% static 'assets/image.jpg' %}) tag in HTML File for calling static files
       # 6 - Done

相关问题