Django报错:使用staticfiles应用却未配置必需的STATIC_URL
解决Django中"You're using the staticfiles app without having set the required STATIC_URL setting"错误
问题原因
你的settings.py文件中静态文件URL配置项拼写错误:将STATIC_URL误写为STATIC_URl(字母L为小写),导致Django的staticfiles应用无法识别该配置,触发报错。
报错回溯
Traceback (most recent call last): File "C:\Users\pytho\AppData\Local\Programs\Python\Python310\lib\threading.py", line 1016, in _bootstrap_inner self.run() File "C:\Users\pytho\AppData\Local\Programs\Python\Python310\lib\threading.py", line 953, in run self._target(*self._args, **self._kwargs) File "D:\python_projects\Webogram\Internal\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper fn(*args, **kwargs) File "D:\python_projects\Webogram\Internal\lib\site- packages\django\core\management\commands\runserver.py", line 157, in inner_run handler = self.get_handler(*args, **options) File "D:\python_projects\Webogram\Internal\lib\site- packages\django\contrib\staticfiles\management\commands\runserver.py", line 35, in get_handler return StaticFilesHandler(handler) File "D:\python_projects\Webogram\Internal\lib\site- packages\django\contrib\staticfiles\handlers.py", line 75, in __init__ self.base_url = urlparse(self.get_base_url()) File "D:\python_projects\Webogram\Internal\lib\site- packages\django\contrib\staticfiles\handlers.py", line 30, in get_base_url utils.check_settings() File "D:\python_projects\Webogram\Internal\lib\site- packages\django\contrib\staticfiles\utils.py", line 49, in check_settings raise ImproperlyConfigured( django.core.exceptions.ImproperlyConfigured: You're using the staticfiles app without having set the required STATIC_URL setting.
问题代码(settings.py错误片段)
# 错误拼写:STATIC_URl(小写L) STATIC_URl = "/static/"
修正方案
将配置项拼写修正为正确的STATIC_URL(大写L):
# 正确拼写:STATIC_URL STATIC_URL = "/static/"
修正后重启Django服务,报错即可解决。
内容的提问来源于stack exchange,提问作者user18519195
相关产品推荐
相关产品推荐

