数据存储在localhost上,但不存储在gae数据存储区中?

时间:2012-04-26 04:14:35

标签: python google-app-engine google-cloud-datastore

由于某种原因,我创建的表单将数据插入到localhost上的db中。我将它部署到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

1 个答案:

答案 0 :(得分:1)

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

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

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