简体   繁体   中英

File mapping for Django deployment

I have hammered out my first Django site following the tutorial on the official Django site, with lots of googling on the way. The site would allow me to upload images(stored under the ' media ' folder) and have them displayed. It works fine locally on firefox. Now I am stuck on how to deploy it. I have mainly followed instructions on flailingmonkey.com to try to setup the production environment on justhost. I modified the settings and reorganized folders according to this page by the author of "Two Scoops of Django" . My local file structure looks something like this.

C:\django_projects
    +---< my_project >
    |    +---< my_project >
    |    |    |--- settings.py
    |    |    |--- urls.py
    |    |    |--- wsgi.py
    |    |    |--- __init__.py
    |    |
    |    +---< my_app >
    |         +---< static >
    |         |    +---< my_app >
    |         |         +---< css >
    |         |         |    |--- style.css
    |         |         +---< script >
    |         |              |--- my_javascript.js
    |         +---< templates >
    |         +---< migrations >
    |         +---< __pycache__ >
    |         |--- admin.py
    |         |--- urls.py
    |         |--- models.py
    |         |--- views.py
    |         |--- __init__.py
    |    
    +---\assets
    |    +---< admin >
    |    +---< my_app >
    |         +---< css >
    |         |    |--- style.css
    |         +---< script >
    |              |--- my_javascript.js
    |
    +---\static
    |
    +---\media

As I understand, I should use ' collectstatic ' to gather all static files(css, scripts) before deployment, which I have performed(as reflected in the folder structure).

Last time I did any web dev was about 10 years ago, and I remember all that I had to do in the past was dumping everything under the public_html folder. In the case of Django dev, is it anything different? Should I ftp the four folders(namely ' my_project ', ' assets ', ' static ', ' media ') above into public_html to the remote server? Or should I ftp the entire ' django_projects ' folder? Do I need to place ' my_project ', which contains settings.py , somewhere outside ' public_html '? What about the ' assets ' and ' media ' folders?

Instruction on flailingmonkey.com does not clearly state locations for the project folder and app folder. I have tried blindly for 3 days and been struggling with static files not being served. I have not tried to place everything under public_html , because it seems to me to be an unsafe practice to put setting file there, which contains database credential. Please advise.

This might be a silly question to most of you. Thank you for your patience for reading such a long-winded question. I am trying to make this as clear as possible.

PS Other than writing up the .htaccess and my_app.fcgi files as instructed, I can think of changing the ' DEBUG ' in settings.py to ' False '. Is there anything still missing for a deployment?

You would not put the django project into public_html. Normally, Django will talk to mod_wsgi (Apache) or uWSGI (nginx) and serve the dynamic content back to the server process using the wsgi protocol. The static content (images, javascript, etc) is normally mapped to a server-side directory.

I recommend reading the deployment page on the Django project page: https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/modwsgi/

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