django-nonrel on gae没有看到管理员静态文件

时间:2013-09-01 10:29:49

标签: python django google-app-engine

我设法让django-nonrel使用谷歌应用引擎

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

管理文件夹的路径和文件结构显示为here

它也无法打开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'}),
)

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,我已经解决了以下问题。

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

'django.contrib.staticfiles',

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

STATIC_URL = '/static/'

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

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

我猜你应该在你的app yaml文件中避免使用django库定义,因为你使用的是djangononrel。因此,下面的定义是没有必要的

libraries:
- name: django
  version: latest