AttributeError: has no attribute 'STATIC'
AttributeError: has no attribute 'STATIC'
所以一直在尝试在 Python 上启动我的服务器(我是 Python、Django 的新手)下面是我的 运行 我的服务器的代码,可以看到这里 https://shrib.com/#Meerkat9GKd1xx
当我 运行 代码时,我得到以下属性错误:
]+static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)+static(settings.STATIC_URL,document_root=settings.STATIC.ROOT)
AttributeError: module 'student_management_system.settings' has no attribute 'STATIC'
我该如何解决这个问题?
在您的 settings.py
文件和 urls.py
文件中更改它,如下所示:
settings.py :
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, '/static')
STATICFILES_DIR = os.path.join(BASE_DIR, '/static')
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
urls.py :
from django.contrib import admin
from django.urls import path
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
]
if settings.DEBUG:
urlpatterns+=static(settings.STATIC_URL , document_root=settings.STATIC_ROOT)
urlpatterns+= static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
所以一直在尝试在 Python 上启动我的服务器(我是 Python、Django 的新手)下面是我的 运行 我的服务器的代码,可以看到这里 https://shrib.com/#Meerkat9GKd1xx 当我 运行 代码时,我得到以下属性错误:
]+static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)+static(settings.STATIC_URL,document_root=settings.STATIC.ROOT)
AttributeError: module 'student_management_system.settings' has no attribute 'STATIC'
我该如何解决这个问题?
在您的 settings.py
文件和 urls.py
文件中更改它,如下所示:
settings.py :
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, '/static')
STATICFILES_DIR = os.path.join(BASE_DIR, '/static')
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
urls.py :
from django.contrib import admin
from django.urls import path
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
]
if settings.DEBUG:
urlpatterns+=static(settings.STATIC_URL , document_root=settings.STATIC_ROOT)
urlpatterns+= static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)