2

出于某种原因,我创建的表单将数据插入到本地主机上的数据库中。我将它部署到 gae,表单工作但没有任何内容插入数据存储区?

这是我的模型文件:

from django.db import models
# from django.contrib.auth.models import User

# Create your models here.
class Company(models.Model):
    id = models.IntegerField(primary_key=True);
    name = models.CharField(max_length=100, null=True);
    address = models.CharField(max_length=100, null=True);
    phone = models.CharField(max_length=15, null=True);
    website = models.CharField(max_length=50, null=True);
    email = models.EmailField(max_length=50, null=True);
    hiring = models.BooleanField(default=False);    
    latitude = models.DecimalField(max_digits=20, decimal_places=10, null=True);
    longitude = models.DecimalField(max_digits=20, decimal_places=10, null=True);
    approved = models.BooleanField(default=False);
    date_added = models.DateTimeField(auto_now_add=True);
    about_us = models.TextField(max_length=500, null=True);

我的表格:

from django import forms
from company.models import Company

class SignUpCompanyForm(forms.ModelForm):
    class Meta:
        model = Company;

我的html表单:

{% block content %} 
    <div id="content">
        <!-- a form for sign up -->
        <form id="sign" action="/sign_up_company" method="post">
            <table>{{ form }}</table>
            <input type="submit" value="Sign Up" />
        </form>
    </div>
{% endblock %}

我的视图功能:

def sign_up(request):
    if request.method == 'POST':
        form = SignUpCompanyForm(request.POST);
        if form.is_valid():
            company = form.save(commit=False);
            company.save();
            # company.put();

    return HttpResponseRedirect('/confirmation');

表单的操作映射到“sign_up”。

当我运行“python manage.py syndb”时,我得到:

C:\Users\Joe\Desktop\test>python manage.py syncdb
Creating tables ...
Installing custom SQL ...
Installing indexes ...
No fixtures found.
Exception AttributeError: "'NoneType' object has no attribute 'mkstemp'" in <bound method DatastoreFileStub.__del__ of <google.appengine.api.datastore_file_stub
.DatastoreFileStub object at 0x029874F0>> ignored

我的 app.yaml:

application: app_name
version: 1
runtime: python27
api_version: 1
threadsafe: yes

builtins:
- remote_api: on

inbound_services:
- warmup

libraries:
- name: django
  version: latest

handlers:
- url: /css
  static_dir: css

- url: /_ah/queue/deferred
  script: djangoappengine.deferred.handler.application
  login: admin

- url: /_ah/stats/.*
  script: djangoappengine.appstats.application

- url: /media/admin
  static_dir: django/contrib/admin/media
  expiration: '0'

- url: /.*
  script: djangoappengine.main.application

我的 index.yaml:

indexes:

- kind: django_admin_log
  properties:
  - name: user_id
  - name: action_time
    direction: desc

- kind: django_content_type
  properties:
  - name: app_label
  - name: name
4

1 回答 1

1

App Engine 不支持 Django 模型。您必须使用 App Engine 的 db.models 或 ndb.models API 编写模型。

另一种选择是使用 Django-nonrel。它是适用于 App Engine 或 MongoDB 的 Django 1.3 的一个分支。这将允许您使用 Django 模型。

在当地取得成功有点奇怪。您的 Django 设置必须配置为使用 SQLite 等 SQL 数据库,它可能实际上并未写入 dev_appserver 数据存储。

于 2012-04-26T05:02:39.023 回答