【问题标题】:django-nonrel on gae not seeing admin static filesgae 上的 django-nonrel 看不到管理静态文件
【发布时间】:2013-09-01 10:29:48
【问题描述】:

我已经设法让 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'}),
)

【问题讨论】:

    标签: python django google-app-engine


    【解决方案1】:

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

    在 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-31
      • 1970-01-01
      • 1970-01-01
      • 2014-07-24
      • 2022-07-22
      • 1970-01-01
      • 2015-08-16
      • 1970-01-01
      相关资源
      最近更新 更多