Drf-yasg: Can't resolve static files after SECRET_KEY is changed

Created on 5 Feb 2020  路  2Comments  路  Source: axnsan12/drf-yasg

I can trigger a failure to load swagger when SECRET_KEY in django's settings.py file is changed. There is no such failure with redoc, though there are some load failures.

[05/Feb/2020 19:52:03] "GET / HTTP/1.1" 200 1645
[05/Feb/2020 19:52:03] "GET /static/drf-yasg/style.css HTTP/1.1" 404 179
[05/Feb/2020 19:52:03] "GET /static/drf-yasg/swagger-ui-dist/swagger-ui.css HTTP/1.1" 404 179
[05/Feb/2020 19:52:03] "GET /static/drf-yasg/url-polyfill.min.js HTTP/1.1" 404 179
[05/Feb/2020 19:52:03] "GET /static/drf-yasg/swagger-ui-init.js HTTP/1.1" 404 179
[05/Feb/2020 19:52:03] "GET /static/drf-yasg/swagger-ui-dist/swagger-ui-bundle.js HTTP/1.1" 404 179
[05/Feb/2020 19:52:03] "GET /static/drf-yasg/swagger-ui-dist/swagger-ui-standalone-preset.js HTTP/1.1" 404 179
[05/Feb/2020 19:52:03] "GET /static/drf-yasg/insQ.min.js HTTP/1.1" 404 179
[05/Feb/2020 19:52:03] "GET /static/drf-yasg/immutable.min.js HTTP/1.1" 404 179
[05/Feb/2020 19:52:03] "GET /static/drf-yasg/swagger-ui-dist/swagger-ui-standalone-preset.js HTTP/1.1" 404 179
[05/Feb/2020 19:52:03] "GET /static/drf-yasg/insQ.min.js HTTP/1.1" 404 179
[05/Feb/2020 19:52:03] "GET /static/drf-yasg/immutable.min.js HTTP/1.1" 404 179
[05/Feb/2020 19:52:03] "GET /static/drf-yasg/url-polyfill.min.js HTTP/1.1" 404 179
[05/Feb/2020 19:52:03] "GET /static/drf-yasg/swagger-ui-init.js HTTP/1.1" 404 179
[05/Feb/2020 19:54:06] "GET /swagger/ HTTP/1.1" 200 1645
[05/Feb/2020 19:54:07] "GET /static/drf-yasg/style.css HTTP/1.1" 404 179
[05/Feb/2020 19:54:07] "GET /static/drf-yasg/swagger-ui-dist/swagger-ui.css HTTP/1.1" 404 179
[05/Feb/2020 19:54:07] "GET /static/drf-yasg/url-polyfill.min.js HTTP/1.1" 404 179
[05/Feb/2020 19:54:07] "GET /static/drf-yasg/swagger-ui-dist/swagger-ui-bundle.js HTTP/1.1" 404 179
[05/Feb/2020 19:54:07] "GET /static/drf-yasg/swagger-ui-dist/swagger-ui-standalone-preset.js HTTP/1.1" 404 179
[05/Feb/2020 19:54:07] "GET /static/drf-yasg/swagger-ui-init.js HTTP/1.1" 404 179
[05/Feb/2020 19:54:07] "GET /static/drf-yasg/insQ.min.js HTTP/1.1" 404 179
[05/Feb/2020 19:54:07] "GET /static/drf-yasg/immutable.min.js HTTP/1.1" 404 179
[05/Feb/2020 19:54:07] "GET /static/drf-yasg/swagger-ui-dist/swagger-ui-standalone-preset.js HTTP/1.1" 404 179
[05/Feb/2020 19:54:07] "GET /static/drf-yasg/insQ.min.js HTTP/1.1" 404 179
[05/Feb/2020 19:54:07] "GET /static/drf-yasg/immutable.min.js HTTP/1.1" 404 179
[05/Feb/2020 19:54:07] "GET /static/drf-yasg/url-polyfill.min.js HTTP/1.1" 404 179
[05/Feb/2020 19:54:07] "GET /static/drf-yasg/swagger-ui-init.js HTTP/1.1" 404 179
[05/Feb/2020 19:54:10] "GET /redoc/ HTTP/1.1" 200 994
[05/Feb/2020 19:54:11] "GET /static/drf-yasg/insQ.min.js HTTP/1.1" 404 179
[05/Feb/2020 19:54:11] "GET /static/drf-yasg/url-polyfill.min.js HTTP/1.1" 404 179
[05/Feb/2020 19:54:11] "GET /static/drf-yasg/style.css HTTP/1.1" 404 179
[05/Feb/2020 19:54:11] "GET /static/drf-yasg/url-polyfill.min.js HTTP/1.1" 404 179
[05/Feb/2020 19:54:12] "GET /redoc/?format=openapi HTTP/1.1" 200 11593

```{settings.py}
import os
import configparser

secrets_file = configparser.ConfigParser()
secrets_file.read("secrets.cfg")

Build paths inside the project like this: os.path.join(BASE_DIR, ...)

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

Quick-start development settings - unsuitable for production

See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/

SECURITY WARNING: keep the secret key used in production secret!

SECRET_KEY = secrets_file["DJANGO"]["secret_key"]

SECURITY WARNING: don't run with debug turned on in production!

DEBUG = False

ALLOWED_HOSTS = [
"localhost",
"127.0.0.1",
"[::1]",
"10.6.13.185",
"10.4.72.192",
]

Application definition

INSTALLED_APPS = [
# 'django.contrib.admin',
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"core_lims_adapter.apps.CoreLimsAdapterConfig",
"rest_framework",
"drf_yasg",
]

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",
]

ROOT_URLCONF = "lims_rest.urls"

TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"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",
],
},
},
]

WSGI_APPLICATION = "lims_rest.wsgi.application"

AUTH_PASSWORD_VALIDATORS = [
]

Internationalization

https://docs.djangoproject.com/en/3.0/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/3.0/howto/static-files/

STATIC_URL = "/static/"

REST_FRAMEWORK = {
"DEFAULT_PERMISSION_CLASSES": ["rest_framework.permissions.AllowAny"],
"UNAUTHENTICATED_USER": None,
}

SWAGGER_SETTINGS = {
"SECURITY_DEFINITIONS": {"basic": {"type": "basic"}},
"USE_SESSION_AUTH": False,
}
```

Most helpful comment

so, how to solve this problem?

All 2 comments

Very dumb mistake.

so, how to solve this problem?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

littlehome-eugene picture littlehome-eugene  路  4Comments

maikotz picture maikotz  路  4Comments

phihag picture phihag  路  3Comments

geekashu picture geekashu  路  5Comments

mkurnikov picture mkurnikov  路  4Comments