数据存储在localhost上,但不存储在gae数据存储上? [英] data is stored on localhost but not on gae datastore?

查看:111
本文介绍了数据存储在localhost上,但不存储在gae数据存储上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于某种原因,我创建的表单将数据插入localhost上的数据库。我将它部署到gae,表单可以工作,但是没有任何东西被插入到数据存储中?



这是我的模型文件:

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

#在这里创建模型。
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 form 
from company.models import Company
$ b class SignUpCompanyForm(forms.ModelForm):
class Meta:
model = Company ;

我的html表单:

  {%block content%} 
< div id =content>
<! - 注册表单 - >
< form id =signaction =/ sign_up_companymethod =post>
< table> {{form}}< / table>
< input type =submitvalue =注册/>
< / 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 
创建表...
安装自定义SQL ...
安装索引...
未找到任何固件。
Exception AttributeError:''NoneType'对象在< google.appengine.api.datastore_file_stub
.DatastoreFileStub对象在0x029874F0><绑定方法DatastoreFileStub .__ del__中没有属性'mkstemp'忽略

我的app.yaml:



<$ p






















$ b $
- remote_api:在

inbound_services:
- 预热

库:
- 名称:django
版本:latest

处理程序:
- url:/ css
static_dir:css
$ b - url:/ _ah / queue / deferred
script:djangoappengine。 deferred.handler.application
登录名:admin

- url:/_ah/stats/.*
脚本:djangoappengine.appstats.application

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

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

我的index.yaml:

 索引:

- kind:django_admin_log
属性:
- name:user_id
- name:action_time
方向:desc

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


解决方案

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



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



它在本地成功有点奇怪。您的Django安装程序必须配置为使用SQLite之类的SQL数据库,它可能不会真正写入dev_appserver数据存储区。


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

解决方案

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.

这篇关于数据存储在localhost上,但不存储在gae数据存储上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆