Код: Выделить всё
urlpatterns += static(settings.STATIC_URL,document_root=settings.STATIC_ROOT)
Ранее у меня была аналогичная проблема с загрузкой медиафайлов, но ее легко исправить с помощью< /p>
Код: Выделить всё
urlpatterns += static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)
В моем проекте используется сервер выполнения, который, судя по другим ответам, не самый лучший, хотя я использую этот проект только локально на своем ПК. Мои файлы следующие:
socialnetwork/landing/templates/base.html
Код: Выделить всё
{% load static %}
Social Network
{% include 'landing/navbar.html' %}
{% block content %}
{% endblock content %}
Код: Выделить всё
from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('landing.urls')),
path('accounts/', include('allauth.urls')),
path('social/', include('social.urls')),
]
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL,document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Код: Выделить всё
INSTALLED_APPS = [
'socialnetwork',
'social',
'static',
'landing',
'allauth',
'crispy_forms',
'crispy_bootstrap5',
'allauth.account',
'allauth.socialaccount',
'django.contrib.admin',
'django.contrib.auth',
"django.contrib.sites",
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
Код: Выделить всё
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
]
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
Для отображаемой страницы (post_list.html) соответствующие представления в Socialnetwork/ Social/views.py возвращает render(request, 'social/post_list.html', context). Наконец, моя файловая структура выглядит примерно так:
Код: Выделить всё
social network
> landing
-> templates
-> base.html
> media
> social
-> templates
-> post_list.html
-> models.py
-> urls.py
-> views.py
> socialnetwork
-> settings.py
-> urls.py
> static
-> admin
-> css
-> style.css
> templates
> manage.py
Подробнее здесь: https://stackoverflow.com/questions/785 ... atic-files
Мобильная версия