Django media URLs in CSS files

后端 未结 4 373
青春惊慌失措
青春惊慌失措 2021-02-02 07:12

In django templates, it\'s common to do the following:


How would you accomplish this in a

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-02 07:58

    Sorry, you won't like the answer.

    I've got the same problem:

    There is no easy way to do this with static-served CSS files.

    What I do:

    • debug server, work locally, media served locally
    • production server is hosted out somewhere commercial w/media on Amazon S3
    • settings.py file auto sets MEDIA_URL (DEBUG, etc.) via hostname check (to differentiate production vs. local/home/debug)
    • HTML files all have css links with {{MEDIA_URL}} (+RequestContext contexts for views)
    • I like absolute path names, so an "update_s3" script: (1) alters each css file is temporarily to fix 'url("/media' to 'url("s3.mydomain.com/media' and (2) updates/uploads my /media directory to Amazon S3

    I then go to production and do an svn update & touch the WSGI file & validate

提交回复
热议问题