简体   繁体   中英

Django moving from Development server to Deployment Server

Regarding this documentation page from the Django website,

https://docs.djangoproject.com/en/1.2/howto/static-files/

where it says for development "With that said, Django does support static files during development. You can use the django.views.static.serve() view to serve media files."

So my question is, if I use this method, How much work is required to move to apache.

Currently I have a symbolic link to my image folder in the /var/www folder, and in the Django settings I have set the media url to :

MEDIA_URL = 'http://127.0.0.1:80/Images/'

This seems like a fairly easy hack but my project is going to get very big (with lots of css, js and pdfs) and I doubt if this method is good.

This is a perfectly good way of doing things. The only change you'll need to make is to put the actual URL of your site, rather than the localhost IP.

My approach was to have apache itself intercept the static files urls and serve them directly without invoking django at all. So my apache config looked something like this:

<VirtualHost *:80>
    ServerName www.myproject.com


    Alias /static /docs/my_website/static
    <Directory /docs/my_website/static>
            Order allow,deny
            Allow from all
    </Directory>

    Alias /favicon.ico /docs/my_website/static/images/icons/favicon.ico

    Include "/13parsecs/conf/django.conf"
</VirtualHost>

Then you can just keep doing whatever you're doing in the dev environment, and when you get to apache it won't invoke django at all for static content, which is what you want.

Don't "move to Apache", start using it in the first place. None of the software needed has licensing fees and runs on almost any platform, so the only excuse you could have is "I'm too lazy".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM