data is stored on localhost but not on gae datasto

2019-05-22 23:23发布

For some reason, the form I created inserts data into the db on localhost. I deployed it to gae, the form works but nothing is been inserted into the datastore?

Here is my models file:

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);

My form:

from django import forms
from company.models import Company

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

My html form:

{% 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 %}

My view function:

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');

The action of the form is mapped to "sign_up".

When I run "python manage.py syndb" I get:

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

My 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

My 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条回答
何必那么认真
2楼-- · 2019-05-22 23:58

App Engine does not support Django models. You have to write your models using App Engine's db.models or ndb.models API.

The other option is to use Django-nonrel. It's a fork of Django 1.3 that works on App Engine or MongoDB. This will allow you to use Django models.

It's a bit odd that it's succeeding locally. Your Django setup must be configured to use some SQL database like SQLite, it's probably not actually writing to the dev_appserver datastore.

查看更多
登录 后发表回答