Не подгружается static файлы
Писал проект на Django. Вылил его на сервер, на сервере static подгружается корректно. После чего решил дописать ещё функционал, но на локальной машине, однако перестала подгружаться static.
Файл url.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('accounts/', include('social_auth.urls')),
path('', include('pb_admin.urls')),
path('jet/', include('jet.urls', 'jet')),
path('admin/', admin.site.urls),
]
Файл setting.py
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
ALLOWED_HOSTS = ['127.0.0.1']
# Application definition
INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.sites',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.google',
'jet',
'django.contrib.admin',
'rest_framework_bulk',
'apps_generic.whodidit',
'rest_framework.authtoken',
# futures
'my_app',
'pb_admin',
'social_auth',
'corsheaders',
]
REST_FRAMEWORK = {
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'PAGE_SIZE': 10,
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.BasicAuthentication',
'rest_framework.authentication.SessionAuthentication',
],
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.AllowAny',
],
}
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'apps_generic.whodidit.middleware.RequestMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
]
ROOT_URLCONF = 'my_app.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, "templates")],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'django.template.context_processors.request',
],
},
},
]
WSGI_APPLICATION = 'my_app.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join (BASE_DIR, "static")
# Django all auth settings
AUTHENTICATION_BACKENDS = (
# Need to login by username in Django admin, regardlessof `allauth`
'django.contrib.auth.backends.ModelBackend',
# `allauth` specific authentication methods, such as login by email
'allauth.account.auth_backends.AuthenticationBackend',
)
SITE_ID = 1
CORS_ORIGIN_ALLOW_ALL = False
CORS_ORIGIN_WHITELIST = [
'http://localhost:3000'
]
CORS_ALLOW_HEADERS = [
'accept',
'accept-encoding',
'authorization',
'content-type',
'dnt',
'origin',
'user-agent',
'x-csrftoken',
'x-requested-with',
]
Ошибка при вызове url
Performing system checks...
System check identified no issues (0 silenced).
October 06, 2020 - 21:07:04
Django version 2.2.14, using settings 'my_app.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
[06/Oct/2020 21:07:07] "GET /admin/login/?next=/admin/ HTTP/1.1" 200 4437
[06/Oct/2020 21:07:07] "GET /static/admin/css/base.css HTTP/1.1" 404 77
[06/Oct/2020 21:07:07] "GET /static/jet/css/vendor.css?v=1.0.8 HTTP/1.1" 404 77
[06/Oct/2020 21:07:07] "GET /static/admin/css/login.css HTTP/1.1" 404 77
[06/Oct/2020 21:07:07] "GET /jet/jsi18n/ HTTP/1.1" 200 3223
[06/Oct/2020 21:07:07] "GET /static/jet/js/build/bundle.min.js?v=1.0.8 HTTP/1.1" 404 77
[06/Oct/2020 21:07:07] "GET /static/jet/css/icons/style.css?v=1.0.8 HTTP/1.1" 404 77
[06/Oct/2020 21:07:07] "GET /static/jet/js/i18n/select2/en.js?v=1.0.8 HTTP/1.1" 404 77
[06/Oct/2020 21:07:07] "GET /static/jet/css/themes/default/base.css?v=1.0.8 HTTP/1.1" 404 77
[06/Oct/2020 21:07:07] "GET /static/jet/css/themes/default/select2.theme.css?v=1.0.8 HTTP/1.1" 404 77
[06/Oct/2020 21:07:07] "GET /static/jet/css/themes/default/jquery-ui.theme.css?v=1.0.8 HTTP/1.1" 404 77
[06/Oct/2020 21:07:07] "GET /static/jet/js/build/bundle.min.js?v=1.0.8 HTTP/1.1" 404 77
[06/Oct/2020 21:07:07] "GET /static/jet/js/i18n/select2/en.js?v=1.0.8 HTTP/1.1" 404 77
[06/Oct/2020 21:07:08] "GET /favicon.ico HTTP/1.1" 404 77
[06/Oct/2020 21:07:08] "GET /admin/login/?next=/admin/ HTTP/1.1" 200 4437
[06/Oct/2020 21:07:08] "GET /static/jet/css/icons/style.css?v=1.0.8 HTTP/1.1" 404 77
[06/Oct/2020 21:07:08] "GET /static/jet/css/themes/default/select2.theme.css?v=1.0.8 HTTP/1.1" 404 77
[06/Oct/2020 21:07:08] "GET /static/jet/css/vendor.css?v=1.0.8 HTTP/1.1" 404 77
[06/Oct/2020 21:07:08] "GET /static/admin/css/base.css HTTP/1.1" 404 77
[06/Oct/2020 21:07:08] "GET /static/jet/css/themes/default/base.css?v=1.0.8 HTTP/1.1" 404 77
[06/Oct/2020 21:07:08] "GET /static/jet/css/themes/default/jquery-ui.theme.css?v=1.0.8 HTTP/1.1" 404 77
[06/Oct/2020 21:07:08] "GET /static/jet/js/build/bundle.min.js?v=1.0.8 HTTP/1.1" 404 77
[06/Oct/2020 21:07:08] "GET /static/admin/css/login.css HTTP/1.1" 404 77
[06/Oct/2020 21:07:08] "GET /jet/jsi18n/ HTTP/1.1" 200 3223
[06/Oct/2020 21:07:08] "GET /static/jet/js/i18n/select2/en.js?v=1.0.8 HTTP/1.1" 404 77
[06/Oct/2020 21:07:09] "GET /static/jet/js/build/bundle.min.js?v=1.0.8 HTTP/1.1" 404 77
[06/Oct/2020 21:07:09] "GET /static/jet/js/i18n/select2/en.js?v=1.0.8 HTTP/1.1" 404 77
[06/Oct/2020 21:07:09] "GET /favicon.ico HTTP/1.1" 404 77
Пытался так же collectstatic
D:\project\pb_adm\my_app>python manage.py collectstatic
You have requested to collect static files at the destination
location as specified in your settings:
D:\project\pb_adm\my_app\static
This will overwrite existing files!
Are you sure you want to do this?
Type 'yes' to continue, or 'no' to cancel: yes
Found another file with the destination path 'admin\css\base.css'. It will be ignored since only the first encountered file is collected. If this is not what you want, make sure every static file has a unique path.
Found another file with the destination path 'admin\css\changelists.css'. It will be ignored since only the first encountered file is collected. If this is not what you want, make sure every static file has a unique path.
Found another file with the destination path 'admin\css\dashboard.css'. It will be ignored since only the first encountered file is collected. If this is not what you want, make sure every static file has a unique path.
Found another file with the destination path 'admin\css\fonts.css'. It will be ignored since only the first encountered file is collected. If this is not what you want, make sure every static file has a unique path.
Found another file with the destination path 'admin\css\forms.css'. It will be ignored since only the first encountered file is collected. If this is not what you want, make sure every static file has a unique path.
Found another file with the destination path 'admin\css\login.css'. It will be ignored since only the first encountered file is collected. If this is not what you want, make sure every static file has a unique path.
Found another file with the destination path 'admin\css\rtl.css'. It will be ignored since only the first encountered file is collected. If this is not what you want, make sure every static file has a unique path.
Found another file with the destination path 'admin\css\widgets.css'. It will be ignored since only the first encountered file is collected. If this is not what you want, make sure every static file has a unique path.
Found another file with the destination path 'admin\js\SelectFilter2.js'. It will be ignored since only the first encountered file is collected. If this is not what you want, make sure every static file has a unique path.
Found another file with the destination path 'admin\js\admin\DateTimeShortcuts.js'. It will be ignored since only the first encountered file is collected. If this is not what you want, make sure every static file has a unique path.
Found another file with the destination path 'admin\js\admin\RelatedObjectLookups.js'. It will be ignored since only the first encountered file is collected. If this is not what you want, make sure every static file has a unique path.
0 static files copied to 'D:\project\pb_adm\my_app\static', 427 unmodified.
Ответы (1 шт):
Автор решения: Andrey Maslov
→ Ссылка
по умолчанию django не обслуживает статические файлы, этим должен заниматься web-server, но если ты хочешь на локальной машине для отладки использовать django и тебе нужно отображение статических файлов, то в urls.py нужно дописать
...
from django.conf import settings
from django.conf.urls.static import static
...
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)