现在我是 Heroku 的新手,并尝试在 Heroku 上部署我的 Django 应用程序。只需按照说明操作就成功了,我可以在 heroku 中进行测试。但是当我将本地数据库从 sqlite 更改为 postgres 后,由于错误,我无法进一步操作。可能和DB有关。我的应用程序在本地基地仍然运行良好,但在 Heroku 中却不行,而我将所有应用程序都推送到了 Heroku。
基础.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'postgres',
'USER': 'postgres',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}
db_from_env = dj_database_url.config()
DATABASES['default'].update(db_from_env)
Run Code Online (Sandbox Code Playgroud)
调试模式下的错误消息
ProgrammingError at /
relation "django_session" does not exist
LINE 1: ...ession_data", "django_session"."expire_date" FROM "django_se...
^
Request Method: GET
Request URL: https://happybom.herokuapp.com/
Django Version: 2.0.4
Exception Type: ProgrammingError
Exception Value:
relation "django_session" does not exist
LINE 1: ...ession_data", "django_session"."expire_date" FROM …Run Code Online (Sandbox Code Playgroud) 我想向我的查询集中添加一些额外的字段。
模型.py
class Company(models.Model):
ENTITY_CHOICES = ( ('CO', 'Corporation'),('PR','Proprietor'),('PA','Partnership'),('NO','Nonprofit'))
legal_name = models.CharField(max_length=120, blank=True)
entity = models.CharField(max_length=1, null=True, choices=ENTITY_CHOICES, default='CO')
client = models.ForeignKey(Clients, models.SET_NULL, blank=True, null=True)
Run Code Online (Sandbox Code Playgroud)
视图.py
qs = Company.objects.filter(entity=PA)
for q in qs:
q.due_date = '06/15'
for q in qs:
print('due_date',q.due_date)
Run Code Online (Sandbox Code Playgroud)
它成功了很多次。但结果并不稳定,我碰巧看到如下错误,
Exception Type: AttributeError
Exception Value:
'Companies' object has no attribute 'due_date'
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法向查询集添加额外的属性?
我开发了基于Python 3.6和Django 2.0的Web应用程序,并希望首次在Google App Engine中进行部署。当我尝试部署(gcloud app deploy)时,它没有通过,并显示以下错误消息:
(acct) C:\Users\tsjee_000\dev\acct\src>gcloud app deploy
ERROR: (gcloud.app.deploy) An error occurred while parsing file: [C:\Users\tsjee_000\dev\acct\src\app.yaml]
libraries entries are only supported by the "python27" runtime
in "C:\Users\tsjee_000\dev\acct\src\app.yaml", line 34, column 13
Run Code Online (Sandbox Code Playgroud)
app.yaml:
runtime: python
api_version: 1
threadsafe: yes
env: flex
entrypoint: gunicorn -b :$PORT main:app
handlers:
- url: /static
static_dir: static/
- url: .*
script: acct.wsgi.application
libraries:
- name: MySQLdb
version: 1.2.5
Run Code Online (Sandbox Code Playgroud)
GAE还不支持Python 3和Django 2吗?我寻找答案,并尝试了多种方法,但是没有用。