Location of Django Admin media files in the Google App Engine

I am running GoogleAppEngine (GAE) 1.6.3 with Python 2.7 and Django 1.3, having:

libraries: - name: django version: "1.3" 

in my app.yaml . The following should serve admin media files at url /static/admin :

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

But I get 404s for such administration tools (css, etc.). Am I using the correct location for the Django media file?

+3
source share
5 answers

The best way to do this is to copy or symbolize the media directory to your application directory in local files so that it is loaded with your application files. Then your app.yaml can refer to the relative path in the application directory.

There is a $PYTHON_LIB variable substitution that you can use in the app.yaml paths, but it seems that Django is not under $PYTHON_LIB in the live version of the Python 2.7 runtime.

+3
source

When adding this parameter to app.yaml

 handlers: - url: /static/admin static_dir: static/admin expiration: '0' 

I was able to serve CSS files:

Adding this value to settings.py :

 BASE_DIR = os.path.abspath(os.path.dirname(__file__)) + os.sep STATIC_ROOT = BASE_DIR + 'static' 

And then run

 python manage.py collectstatic 

Administrator media files display correctly locally, as well as on appspot.com. The last command copies the media to the static/ directory. Therefore, he actually does what Dan Sanderson suggested, but in a more automated way.

+1
source

I tried Philipp Keller collectstatic , but I do not have this team.

So add this handler to app.yaml :

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

then in settings.py remove ADMIN_MEDIA_PREFIX (removed in django 1.4) and add:

 STATIC_URL = '/static/' 

and css works for you.

+1
source

static file referenced by $ PYTHON_LIB when deploying is possible

file app.yaml

 application: hello version: 1 runtime: python27 api_version: 1 threadsafe: true libraries: - name: django version: "1.3" handlers: - url: /admin/media static_dir: $PYTHON_LIB/lib/django_1_3/django/contrib/admin/media builtins: - django_wsgi: on 

local log:

INFO 2012-04-03 02: 06: 19,200 dev_appserver.py:2884] "GET / admin / media / css / base.css HTTP / 1.1" 200 -

INFO 2012-04-03 02: 06: 19,207 dev_appserver.py:2884] "GET / admin / media / css / dashboard.css HTTP / 1.1" 200 -

INFO 2012-04-03 02: 06: 19,242 dev_appserver.py:2884] "GET / admin / media / img / admin / default-bg.gif HTTP / 1.1" 200 -

application for troubleshooting log errors:

2012-04-02 19: 17: 32.775 / admin / media / css / dashboard.css 404 6ms 0kb

    • [02 / Apr / 2012: 19: 17: 32 -0700] "GET / admin / media / css / dashboard.css HTTP / 1.1" 404

No static file referenced by the handler was found: $ PYTHON_LIB / lib / django_1_3 / django / contrib / admin / media / css / dashboard.css

0
source

It seems to me that this works fine.

app.yaml

 handlers: - url: /static static_dir: staticfiles 

Settings

 STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') STATICFILES_DIRS = ( os.path.join(BASE_DIR, 'static'), ) 

Run python manage.py collectstatic . Now an administrator folder should be created under your static file.

0
source

Source: https://habr.com/ru/post/912041/


All Articles