当我尝试启动Django服务器时,出现以下错误。你知道吗
> python manage.py runserver 0.0.0.0:8000
>
> Traceback (most recent call last): File "manage.py", line 10, in
> <module>
> execute_from_command_line(sys.argv) File "/u/agrawalo/beatthestreet/lib/python2.7/site-packages/django/core/management/__init__.py",
> line 363, in execute_from_command_line
> utility.execute() File "/u/agrawalo/beatthestreet/lib/python2.7/site-packages/django/core/management/__init__.py",
> line 307, in execute
> settings.INSTALLED_APPS File "/u/agrawalo/beatthestreet/lib/python2.7/site-packages/django/conf/__init__.py",
> line 56, in __getattr__
> self._setup(name) File "/u/agrawalo/beatthestreet/lib/python2.7/site-packages/django/conf/__init__.py",
> line 41, in _setup
> self._wrapped = Settings(settings_module) File "/u/agrawalo/beatthestreet/lib/python2.7/site-packages/django/conf/__init__.py",
> line 110, in __init__
> mod = importlib.import_module(self.SETTINGS_MODULE) File "/opt/python/python-2.7/lib64/python2.7/importlib/__init__.py", line
> 37, in import_module
> __import__(name) File "/u/agrawalo/beatthestreet/beatthestreet/config/settings.py", line 96,
> in <module>
> 'PORT': config('DB_PORT', cast=int), File "/u/agrawalo/beatthestreet/lib/python2.7/site-packages/decouple.py",
> line 197, in __call__
> return self.config(*args, **kwargs) File "/u/agrawalo/beatthestreet/lib/python2.7/site-packages/decouple.py",
> line 85, in __call__
> return self.get(*args, **kwargs) File "/u/agrawalo/beatthestreet/lib/python2.7/site-packages/decouple.py",
> line 79, in get
> return cast(value) ValueError: invalid literal for int() with base 10: ''
.env中的内容
SECRET_KEY=BeatTheStreet
DEBUG=False
ALLOWED_HOSTS=['*']
EVENT_STARTED=True
EVENT_ENDED=
# Production database details
DB_NAME=
DB_USER=
DB_PASSWORD=
DB_HOST=
DB_PORT=
您需要为DB config设置值。此时
DB_PORT
被设置为空/null,因此无法将其转换为inint
。你知道吗您可以这样再现错误:
基本上在django中,它将端口值作为空字符串获取。因此,您可以检查端口的值是否被正确读取,或者在缺少
PORT
的情况下提供默认值(或者您可以从.env文件中删除该值):相关问题 更多 >
编程相关推荐