我正在尝试在 Cookeicutter 上建立一个网站,我创建了一个名为“bots”的新应用程序,并在模型中添加了一个名为 Trade 的类,该类列出了 2 个参数,“标题”和“单位”。迁移并运行服务器后,当我打开管理面板并单击面板内的“+ 添加”按钮以创建交易时(见图)。Django 网页返回此错误:
django.db.utils.ProgrammingError: relation "bot_trade" does not exist
LINE 1: ...."id", "bots_unit"."sell", "bots_unit"."buy" FROM "bots_unit...
Run Code Online (Sandbox Code Playgroud)
附加信息:使用 postgreSQL 在 docker 中运行我的 django
模型.py
from django.db import models
from datetime import date
#from django.contrib.auth.models import AbstractUser
#from .models import User
from django.urls import reverse
from django.urls import reverse_lazy
from django.conf import settings
import uuid
class Unit(models.Model):
TRADE_UNIT = (
('ETH', 'Ethereum'),
('BTC', 'Bitcoin'),
('LTC', 'Litecoin'),
('IOT', 'IOTA'),
('OMG', 'OmiseGo'),
('BCH', 'BitcoinCash'),
)
sell = …Run Code Online (Sandbox Code Playgroud) 我有一个像下面这样的 cookiecuttern json
{
"variable1": "Test variable 1 - mandatory",
"variable2": "Test variable 2"
}
Run Code Online (Sandbox Code Playgroud)
有什么方法可以向这个 cookiecuter 的用户指定该字段variable1是强制性的吗?variable2我不希望用户在不输入值的情况下继续输入值variable1
在用户为变量提供了一些值之后,有没有办法机器生成一些值cookiecutter.json?
我问的原因是:
所以我真的希望能够删除用户提示,并改为计算值.
我试过的事情:
pre_gen_project.py文件以显示如何执行此操作我在命令行上使用cookiecutter:
cookiecutter path_to_template
Run Code Online (Sandbox Code Playgroud)
我错过了任何技巧吗?
我使用 cookiecutter-django 模板开始了我的第一个项目。
当我尝试使用 virtualenv 从 PyCharm 启动它时,它在 lib 文件中给出了一个错误:environ.py,告诉我:
File "/home/madtyn/venvs/nana/lib/python3.6/site-packages/environ.py", line 114
raise ValueError, "No frame marked with %s." % fname
^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)
经过搜索,我咨询了某人,有人向我推荐了另一种方式。正如他们告诉我的那样,我尝试制作一个新的 venv,
python3 -m venv /home/madtyn/venvs/name
Run Code Online (Sandbox Code Playgroud)
激活它
source /home/madtyn/venvs/name/bin/activate
Run Code Online (Sandbox Code Playgroud)
并从命令行运行服务器,但似乎发生了同样的事情。
我不认为我做错了什么。这些是我的规格:
我用两勺Django 1.8推荐了一个使用cookiecutter的django项目.它叫做icecreamratings_project我使用git cmd提示符并使用
'cd icecreamratings_project'.
当我想使用python manage.py shell使用内置的python解释器时,它给了我以下错误.导入环境中的文件"C:\ Users\Armando\Desktop\icecreamratings_project\config\settings\common.py",第13行ImportError:没有名为'environ'的模块
我查看了目录,下面的代码是:
from __future__ import absolute_import, unicode_literals
from sys import path
import environ
ROOT_DIR = environ.Path(__file__) - 3 # (/a/b/myfile.py - 3 = /)
APPS_DIR = ROOT_DIR.path('twoscoops_project')
env = environ.Env()
Run Code Online (Sandbox Code Playgroud)
没有名为environ的模块,但我假设environ参考了虚拟环境.我不熟悉cookiecutter文档或它如何创建django模板,但我创建了一个名为environ的虚拟环境.
之后我得到的信息是环境中没有路径.有人可以帮忙吗?
我想知道,是否可以根据cookiecutter.json其他参数的值跳过所选参数的提示?例如对于cookiecutter.json:
{
"ask_for_more": ["y", "n"],
"some_parameter": "test"
}
Run Code Online (Sandbox Code Playgroud)
some_parameter如果答案是 ,ask_for_more我想跳过提示n。
是否可以 ?
我对 Postgres 和 Docker 还很陌生,但我正在用 Django 构建一个 web 应用程序,该应用程序在带有 postgresql 数据库的 docker 内运行。我正在尝试通过命令提示符或 pgweb 查看我的 Postgres 数据库。
不幸的是,我似乎根本找不到数据库,我尝试使用 postgres psql 终端命令,但我的数据库没有在里面列出。我的问题是,postgresql 数据库如何存储在 docker-compose 容器中。我需要手动进入容器然后查看数据库吗?我的最终目标是能够看到我在 postgresql 数据库中的所有表和数据的列表。
任何解释 postgresql 数据库如何与 docker-compose 交互的文档都将不胜感激。
谢谢!
我最近刚刚添加了 Pgweb,但这似乎不起作用
本地.YML
version: '2'
volumes:
postgres_data_local: {}
postgres_backup_local: {}
services:
django:
build:
context: .
dockerfile: ./compose/local/django/Dockerfile
depends_on:
- postgres
volumes:
- .:/app
environment:
- POSTGRES_USER=vicki
- USE_DOCKER=yes
ports:
- "8000:8000"
command: /start.sh
postgres:
build:
context: .
dockerfile: ./compose/production/postgres/Dockerfile
volumes:
- postgres_data_local:/var/lib/postgresql/data
- postgres_backup_local:/backups
environment:
- POSTGRES_USER=vicki
pgweb: …Run Code Online (Sandbox Code Playgroud) 到目前为止,我已经尝试了所有建议的方法,但似乎没有任何效果。我用 Cookiecutter 创建了一个新的 Django 项目。我可以在本地并通过我的 Docker 机器运行它,但由于某种原因我无法将它部署到 AWS。我也一直在松散地关注这个文档:
.ebextensions/django.config
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: config/wsgi.py
Run Code Online (Sandbox Code Playgroud)
项目结构
~/project
|-- .ebextensions
|-- `-- django.config
|-- .elasticbeanstalk
|-- `--config.yml
|--config
|-- | ...
|-- | wsgi.py
|-- project
|-- manage.py
Run Code Online (Sandbox Code Playgroud)
当我检查日志时,这是我得到的样本:
Target WSGI script not found or unable to stat: /opt/python/current/app/application.py
Run Code Online (Sandbox Code Playgroud)
当我运行 eb config 我得到这些设置:
aws:elasticbeanstalk:container:python:
NumProcesses: '1'
NumThreads: '15'
StaticFiles: /static/=static/
WSGIPath: application.py
Run Code Online (Sandbox Code Playgroud)
我试过编辑它,移动 wsgi.py 文件,重命名它,但没有任何效果。我究竟做错了什么?
python django amazon-web-services amazon-elastic-beanstalk cookiecutter
我正在创建一个 cookiecutter 模板,并且仅当变量具有给定值时才添加文件夹(及其包含的文件)。例如 cookiecutter.json:
\n{\n "project_slug":"project_folder"\n "i_want_this_folder":['y','n']\n}\nRun Code Online (Sandbox Code Playgroud)\n我的模板结构如下所示:
\ntemplate\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 {{ cookiecutter.project_slug }}\n \xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 config.ini\n \xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 data\n \xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 data.csv\n \xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 {% if cookiecutter.i_want_this_folder == 'y' %}my_folder{% endif %}\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 some_files\n\nRun Code Online (Sandbox Code Playgroud)\n但是,当运行cookiecutter template并选择“n”时,我收到错误
Error: "~/project_folder" directory already exists\nRun Code Online (Sandbox Code Playgroud)\n我的文件夹名称语法正确吗?
\n我想在 hooks/pre_gen_project.py 中使用动态变量。
当我在挂钩文件中添加静态文本时,它会起作用:
{{ cookiecutter.update({"venv_path": "static/venvpath", "py_path": "static/pypath"}) }}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用像这样的变量时venv_path_val
venv_path_val = "static/venvpath"
py_path_val = "static/pypath"
{{ cookiecutter.update({"venv_path": venv_path_val, "py_path": py_path_val }) }}
Run Code Online (Sandbox Code Playgroud)
我正进入(状态
jinja2.exceptions.UndefinedError:'venv_path_val'未定义
我也在里面尝试过,eval但没有运气:
eval("{{ '{{'|safe }} cookiecutter.update({'venv_path': venv_path, 'py_path': py_path}) {{ '}}'|safe }}")
Run Code Online (Sandbox Code Playgroud)
那么有没有办法将我的动态模板变量注入 cookiecutter 中?
cookiecutter ×10
python ×6
django ×5
postgresql ×2
containers ×1
docker ×1
git ×1
jinja2 ×1
python-3.x ×1
shell ×1