0

我已经设法让 django-nonrel 与谷歌应用引擎一起工作

唯一的问题是,当我进入管理员。它似乎没有看到静态文件。

管理员文件夹的路径和文件结构显示在这里

它也无法打开 setuptools-1.1-py2.7.egg',尽管它位于 site-packages 文件夹中。

我已经开始使用 djangoproject 网站上的官方投票教程对此进行测试。

INFO     2013-09-01 09:25:52,707 dev_appserver_multiprocess.py:656] Running application dev~ctst on port 8000: http://127.0.0.1:8000
INFO     2013-09-01 09:25:52,709 dev_appserver_multiprocess.py:658] Admin console is available at: http://127.0.0.1:8000/_ah/admin
WARNING  2013-09-01 09:26:00,803 py_zipimport.py:139] Can't open zipfile C:\Python27\lib\site-packages\setuptools-1.1-py2.7.egg: IOError: [Errno 13] file not accessible: 'C:\\Python27\\lib\\site-packages\\setuptools-1.1-py2.7.egg'
INFO     2013-09-01 09:26:01,279 __init__.py:44] Validating models...
INFO     2013-09-01 09:26:01,562 __init__.py:55] All models validated.
INFO     2013-09-01 09:26:01,835 dev_appserver.py:3091] "GET /admin/ HTTP/1.1" 200 -
INFO     2013-09-01 09:26:02,000 dev_appserver.py:3091] "GET /admin/admin/css/base.css HTTP/1.1" 404 -
INFO     2013-09-01 09:26:02,319 dev_appserver.py:3091] "GET /admin/admin/css/login.css HTTP/1.1" 404 -

这是我的settings.py

# Initialize App Engine and import the default settings (DB backend, etc.).
# If you want to use a different backend you have to remove all occurences
# of "djangoappengine" from this file.
from djangoappengine.settings_base import *

import os

# Activate django-dbindexer for the default database
DATABASES['native'] = DATABASES['default']
DATABASES['default'] = {'ENGINE': 'dbindexer', 'TARGET': 'native'}
AUTOLOAD_SITECONF = 'indexes'

SECRET_KEY = 'I have a secret key in my file but I can't show it here'

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.contenttypes',
    'django.contrib.auth',
    'django.contrib.sessions',
    'djangotoolbox',
    'autoload',
    'dbindexer',

    # djangoappengine should come last, so it can override a few manage.py commands
    'djangoappengine',
    'polls',
)

    MIDDLEWARE_CLASSES = (
    # This loads the index definitions, so it has to come first
    'autoload.middleware.AutoloadMiddleware',

    'django.middleware.common.CommonMiddleware',
   'django.contrib.sessions.middleware.SessionMiddleware',
   'django.contrib.auth.middleware.AuthenticationMiddleware',
)

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.contrib.auth.context_processors.auth',
    'django.core.context_processors.request',
    'django.core.context_processors.media',
)

# This test runner captures stdout and associates tracebacks with their
# corresponding output. Helps a lot with print-debugging.
TEST_RUNNER = 'djangotoolbox.test.CapturingTestSuiteRunner'

ADMIN_MEDIA_PREFIX = '/media/admin/'
TEMPLATE_DIRS = (os.path.join(os.path.dirname(__file__), 'templates'),)

ROOT_URLCONF = 'urls'

这是我的 app.yaml 文件

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

builtins:
- remote_api: on

inbound_services:
- warmup

libraries:
- name: django
  version: latest

handlers:
- 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

我的 urls.py 文件如下所示:

from django.conf.urls.defaults import *
from django.contrib import admin

admin.autodiscover()

handler500 = 'djangotoolbox.errorviews.server_error'

urlpatterns = patterns('',
    (r'^admin/', include(admin.site.urls)),
    ('^_ah/warmup$', 'djangoappengine.views.warmup'),
    ('^$', 'django.views.generic.simple.direct_to_template',
     {'template': 'home.html'}),
)
4

1 回答 1

0

我有同样的问题,我已经解决了如下。

将以下行放在 settings.py 中已安装的应用程序部分中:

'django.contrib.staticfiles',

我的静态 URL 部分定义如下(我不使用 ADMIN_MEDIA_PREFIX)

STATIC_URL = '/static/'

最后,我的 app.yaml 中的 /static/adimn url 处理程序如下所示

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

而且我想您应该避免在您的应用程序 yaml 文件中使用 django 库定义,因为您使用的是 djangononrel。因此不需要以下定义

libraries:
- name: django
  version: latest
于 2013-10-26T09:54:44.717 回答