AttributeError:没有属性“ STATIC”

时间:2020-08-28 14:42:13

标签: python django pycharm attributes

因此,我一直试图在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'

如何解决此问题?

1 个答案:

答案 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)