Django谷歌应用程序引擎

2024-03-29 00:56:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在努力开发我公司的一些应用程序和django。我在尝试操作时遇到了这个错误管理.py同步数据库。在

Error: No module named appengine_django

以下是我的档案: 设置.py在

 # Django settings for blogproject project.

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
    # ('Your Name', 'your_email@domain.com'),
)

MANAGERS = ADMINS

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': '',                      # Or path to database file if using sqlite3.
        'USER': '',                      # Not used with sqlite3.
        'PASSWORD': '',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    }
}

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# On Unix systems, a value of None will cause Django to use the same
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'America/Chicago'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True

# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = ''

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = ''

# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
# trailing slash.
# Examples: "http://foo.com/media/", "/media/".
ADMIN_MEDIA_PREFIX = '/media/'

# Make this unique, and don't share it with anybody.
SECRET_KEY = 'p1!_$6n7#wet&ibfx+p&y!gfo!vegjgdz9-#us5gj7dir)d)n0'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
#     'django.template.loaders.eggs.Loader',
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',

)

ROOT_URLCONF = 'blogproject.urls'

TEMPLATE_DIRS = (
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
)

INSTALLED_APPS = (
    'appengine_django',
    'blogproject.blogs',

    # Uncomment the next line to enable the admin:
    # 'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
)

在网址.py在

^{pr2}$

在视图.py在

from django.http import HttpResponse, HttpResponseRedirect
from blogs.poll import models
import bforms
from django.shortcuts import render_to_response

def render(template, payload):
    payload['recents'] = models.Poll.all().order('-created_on').fetch(5)
    return render_to_response(template, payload)

def index(request):
    polls = models.Poll.all().order('-created_on').fetch(20)
    payload = dict(polls = polls)
    return render('index.html', payload)

def create(request):
    if request.method == 'GET':
        pollform = bforms.PollForm()
        choiceforms = []
        for i in range(4):
            choiceforms.append(bforms.ChoiceForm(prefix = 'f%s'%i))
    if request.method == 'POST':
        pollform = bforms.PollForm(request.POST)
        choiceform = bforms.ChoiceForm()
        if pollform.is_valid():
            poll = pollform.save()
            choiceforms = []
            for i in range(4):
                choiceforms.append(bforms.ChoiceForm(poll=poll, prefix = 'f%s'%i, data=request.POST))
            for form in choiceforms:
                if form.is_valid():
                    form.save()
            return HttpResponseRedirect(poll.get_absolute_url())
    payload = dict(pollform=pollform, choiceforms=choiceforms)
    return render('create.html', payload)

def poll_detail(request, poll_key):
    poll = models.Poll.get(poll_key)
    choices = models.Choice.all().filter('poll = ', poll)
    if request.method == 'POST':
        choice_key = request.POST['value']
        choice = models.Choice.get(choice_key)
        choice.votes += 1
        choice.put()
        return HttpResponseRedirect('./results/')
    payload = dict(poll = poll, choices = choices)
    return render('poll_details.html', payload)

def poll_results(request, poll_key):
    poll = models.Poll.get(poll_key)
    choices = models.Choice.all().filter('poll = ', poll)
    payload = dict(poll = poll, choices = choices)
    return render('poll_results.html', payload)

在模型.py在

from appengine_django.models import BaseModel
from google.appengine.ext import db

class Poll(db.Model):
    question = db.StringProperty()
    created_on = db.DateTimeProperty(auto_now_add = 1)
    created_by = db.UserProperty()

    def __str__(self):
        return '%s' %self.question

    def get_absolute_url(self):
        return '/poll/%s/' % self.key()


class Choice(db.Model):
    poll = db.ReferenceProperty(Poll)
    choice = db.StringProperty()
    votes = db.IntegerProperty(default = 0)

请帮我拿这个。在

谢谢


Tags: thetodjangofromimportfordbreturn
2条回答

此链接可能有助于您获得最近完整的django实现: http://allbuttonspressed.com 不过,您可能不需要在所有django中进行修补,就可以达到您想要的效果。试着从手册中的一个例子,在它的基础上,一些没有包括的django内容是表单预览、插件、扩展,但是django模板系统是用GAE构建的,所以我首先分析一下您的项目是否需要完整的django,或者是否可以使用类似于Jinja2+WTFOrms+python2.7gae=My stack的东西。在

在AppEngine中使用Django时,应该使用Django nonrl。Google introduction.

似乎您正在尝试使用名为appengine_django的django应用程序,但无法解析。你安装了吗?你是怎么安装的?在

相关问题 更多 >