How to Upload / Deploy a Django app on the web using Pythonanywhere?
Host Your Web for free |
Python anywhere :
Python anywhere is a popular web IDE, Mostly used for Hosting and managing your web apps online. It provides you an online Console where you can run your commands, It is one of the most easy-to-use Web hosting and managing IDE for you. It is a beginner-friendly Web Hosting service Provider. It also provides a free Subscription where a beginner can host and manage their own Web app on the Python anywhere domain.
Things to make sure of before going to host your Django app :
- Make sure your Django project doesn't have any unapplied Migrations
- Make sure your Django project works properly.
- Make sure you have used static files rather than giving an absolute path.
- Make sure you have collected your static files in a different directory other than static firstly add this to your settings.py file: STATIC_ROOT = os. path.join(BASE_DIR, 'static') and then collect all the static files using this command in the terminal: python manage.py collect static.
Steps to Deploy your Django App :
Step 1: Make your Account on Python anywhere and Log in:
Step 2: Now go to the Web section and Click on Add new Web app.
Step 3: Select Python framework as Django. Select your desired Python version then write your desired app name or let it as it is (Note : Further in the steps We will remove this default app) and then click on next It will take a few minutes Depending on your internet and create automatically a default Django app.
Step 4: Now go to Consoles and click on bash in the new Tab and it will open your online Console (terminal) for your Django app.(don't click while it loads)
Step 5: You can check Whether Your default Django app Successfully Installed or not By writing the command in Bash terminal/console: ls -l
Step 6: Now go to Files and upload your Django Project directory in Zip format. If you do know How to make your directory into a zip Click here and upload your directory and convert it to a zip (Note: It will take a few minutes depending on Your Speed )
Step 7: Now go to the Bash terminal and Check again Your directory using the ls -l command and see if Your zip Directory is Showing or not, then Unzip it using the command: unzip <your_directory_name_with_.zip_extension>
NOTE: YOU CAN CHECK YOUR DEFAULT DJANGO APP WORKING OR NOT BY CLICKING ON CONFIGURATION FOR <YOUR_USERNAEM> IN THE WEB SECTION.
NOTE: If still any error occurs go to settings and turn debug to true and then see the errors in your app.
Step 9: Now go to Web and change the source code to your Django project directory name and change and then change the URL directory of Static files and media files in the Web section (in simple in Place of the default Django app name just write your Django project name ) and then click on given RELOAD button.
NOTE: In the static directory give the location of your Collected static files.
Step 10: Then, go to WSGI configuration FILE in the web section and change all default Django app names to your Django project name (like change my site to office_emp_proj) and save :
Step 11: Then, click on Reload in the Web section and and then open your Web app by clicking on Configurations for <your_app_link> at top of the Web section. You will see an Error: DissallowedHost at /
Step 12: To solve this error, Go to your files section and then navigate to your Django project settings.py open it and change Allowed_Host to ['*'] and DEBUG to False then Reload your app again in the WEb section :
Step 13: At last take a breath and after reloading run your web app :
0 Comments