因此,我一直试图在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'
如何解决此问题?
答案 0 :(得分:0)
在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)