使用cookiecutter-django

时间:2016-05-26 17:05:34

标签: python django cookiecutter-django

我一直在尝试使用cookiecutter-django在本地设置一个新的django项目。我已经按照文档进行了操作,但在尝试运行python manage.py migrate时遇到了错误。

错误回溯。

Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/ubuntu/lasbrisas_project/venv/lib/python3.4/site-  packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/home/ubuntu/lasbrisas_project/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 302, in execute
settings.INSTALLED_APPS
File "/home/ubuntu/lasbrisas_project/venv/lib/python3.4/site-packages/django/conf/__init__.py", line 55, in __getattr__
self._setup(name)
File "/home/ubuntu/lasbrisas_project/venv/lib/python3.4/site-packages/django/conf/__init__.py", line 43, in _setup
self._wrapped = Settings(settings_module)
File "/home/ubuntu/lasbrisas_project/venv/lib/python3.4/site-packages/django/conf/__init__.py", line 99, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/home/ubuntu/lasbrisas_project/venv/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/home/ubuntu/lasbrisas_project/django_condominios/config/settings/local.py", line 11, in <module>
from .common import *  # noqa
File "/home/ubuntu/lasbrisas_project/django_condominios/config/settings/common.py", line 102, in <module>
'default': env.db('DATABASE_URL', default='postgres:///django_condominios'),
File "/home/ubuntu/lasbrisas_project/venv/lib/python3.4/site-packages/environ/environ.py", line 180, in db_url
return self.db_url_config(self.get_value(var, default=default), engine=engine)
File "/home/ubuntu/lasbrisas_project/venv/lib/python3.4/site-packages/environ/environ.py", line 371, in db_url_config
'PORT': _cast_int(url.port),
File "/usr/lib/python3.4/urllib/parse.py", line 156, in port
port = int(port, 10)
ValueError: invalid literal for int() with base 10: 'jd#uhUhey385'

在设置项目时,我真的不知道自己做错了什么,如果你查看我采取的步骤并帮助我找出遗漏的内容,我将不胜感激。

使用cookiecutter-django设置项目的步骤:

pip,virtualenv,PostrgreSQL已安装

  1. pip install cookiecutter
  2. cookiecutter https://github.com/pydanny/cookiecutter-django
  3. 回答cookiecutter问题
  4. 创建virtualenv - virtualenv -p /usr/bin/python3 venv
  5. 激活virtualenv - source venv/bin/activate/
  6. cd intoprojectfolder
  7. 文档说sudo ./install_os_dependencies.sh install但是./install_os_dependencies.sh不在projectroot中,在实用程序/中找到文件
    • cd utility
    • sudo ./install_os_dependencies.sh install
  8. pip install -r requirements/local.txt
  9. 在postgresql中设置db:
    • sudo su - postgres
    • psql
    • CREATE DATABASE myproject;
    • CREATE USER myprojectuser WITH PASSWORD 'password';
    • GRANT ALL PRIVILEGES ON DATABASE myproject TO myprojectuser;
    • \q
  10. 返回tu项目根目录
  11. mv env.example .env
  12. export DATABASE_URL=postgres://myprojectuser:myprojectuserdbpassword@127.0.0.1:5432/myproject
  13. python manage.py migrate
  14. 在那之后,当我得到追溯时,可能会出现什么问题?文档不再显示信息,迁移应该有效。

1 个答案:

答案 0 :(得分:2)

Cookiecutter使用项目名称的slug作为您要使用的开发db的名称。您需要自己创建数据库。

来自您的stacktrace的

是您在settings.py文件中提供问题的行:

File "/home/ubuntu/lasbrisas_project/django_condominios/config/settings/common.py", line 102, in <module>'default': env.db('DATABASE_URL',     default='postgres:///django_condominios'),

它希望找到一个名为 django_condominios 的数据库。

您可以通过运行

来解决此问题
createdb django_condominios

你应该很好地进行迁移。