• Home
  • Subscribe
  • Contribute Us
    • Share Your Interview Experience
  • Contact Us
  • About
    • About CSEstack
    • Campus Ambassador
  • Forum & Discus
  • Tools for Geek
  • LeaderBoard
CSEstack

What do you want to Learn Today?

  • Programming
    • Tutorial- C/C++
    • Tutorial- Django
    • Tutorial- Git
    • Tutorial- HTML & CSS
    • Tutorial- Java
    • Tutorial- MySQL
    • Tutorial- Python
    • Competitive Coding Challenges
  • CSE Subject
    • (CD) Compiler Design
    • (CN) Computer Network
    • (COA) Computer Organization & Architecture
    • (DBMS) Database Management System
    • (DS) Data Structure
    • (OS) Operating System
    • (ToA) Theory of Automata
    • (WT) Web Technology
  • Interview Questions
    • Interview Questions- Company Wise
    • Interview Questions- Coding Round
    • Interview Questions- Python
    • Interview Questions- REST API
    • Interview Questions- Web Scraping
    • Interview Questions- HR Round
    • Aptitude Preparation Guide
  • GATE 2022
  • Linux
  • Trend
    • Full Stack Development
    • Artificial Intelligence (AI)
    • BigData
    • Cloud Computing
    • Machine Learning (ML)
  • Write for Us
    • Submit Article
    • Submit Source Code or Program
    • Share Your Interview Experience
  • Tools
    • IDE
    • CV Builder
    • Other Tools …
  • Jobs

[FREE] How to Deploy Django on PythonAnywhere | FREE Hosting

Aniruddha Chaudhari/3588/0
Django

Do you want to host our own website online for FREE? You are at the right tutorial. I will explain to you how you can deploy your Django website on Pythonanywhere for FREE step-by-step.

You can host any Python web framework-based (Django, Flask, Bottle,…) applications on PythonAnywhere. And it is pretty easy.

1. Create GitHub Repo

GitHub is the source code hosting platform where you can host your project code. If you already have your project code hosted on GitHub, skip this step.

Create your GitHub account, if you don’t have one. Create a new repository on GitHub for your project and push your code.

Set your repository private if you don’t want to make it public. Otherwise, anyone can access your project source code.

If you are new to source code management and hosting, refer Git tutorial. This tutorial will explain you in detail.

2. Create an Account on Pythonanywhere and Deploy Django on Pythonanywhere

First of all, create your account on PythonAnywhere.

Now we are setting up the Django environment to execute your code from GitHub. We are using the PythonAnyWhere tool for easy installation.

Once you create your account, open the dashboard and click on “Bash” under “New Console”.

Dashboard PythonAnywhere Open Bash Console

Run below command. This command will install all the required Python site-packages to host your Django website.

pip3.8 install --user pythonanywhere

Now you have to clone your GitHub repo, install the required Python modules, and host the website. You don’t need to do it manually. Just run the below command and PythonAnyWhere will do all the things required, for you.

pa_autoconfigure_django.py --python=3.8 <github_repo_link>

You will be asked to provide the GitHub username and password. (Note: GitHub is started using the personal access token. You can use it as a password here.)

Following tasks will be executed by the above command to make your Python web app aka website online. (This will save you a lot of effort and time.)

  • Running API sanity checks
  • Cloning your GitHub repository.
  • Creating virtual environment (virtualenv) with Python3.8
  • Installing Python packages from requirements.txt into the virtual environment.
  • Creating web app via API.
  • Adding static files mappings for /static/ and /media/ (The path for the static and media files are mentioned in the settings.py which you can modify.)
  • Updating WSGI file at /var/www/<app_name>_pythonanywhere_com_wsgi.py
  • Updating settings.py (modify ALLOWED_HOST by adding your website URL)
  • Running collectstatic to copy all the static files to one static path for further use in the web app. (To understand the static files in Django, refer to this link.)
  • Running migrate the database. This will make the initial migration required for the database.
  • Reloading your website via API. This is the final step to make your website go live.
running Django website app on PythonAnywhere

Open the website URL in the web browser. You will see your website running. 😀

If this above script fails for any error, use the “--nuke” option. (Note: option --nuke eliminates all the previous changes, delete web app and set it up fresh.)

3. Add Custom Domain URL

In a free account, you have to use the PythonAnywhere URL to access your Django website. If you want to customize the URL to your own domain, you have to upgrade your account. You can start with a very basic plan which costs you $5/month.

The price is very affordable. Isn’t it?

Follow the steps given below.

customize website domain in Pythonanywhere
  1. Login to your Pythonanywhere account and select menu ‘Web’.
  2. Edit and configure a new domain name or website URL.
  3. You will get the CNAME for DNS setup. Copy that. And set that CNAME as a DNS record with your domain registrar.
  4. Reload the website.

BOOM 😀 Your website is LIVE.

Note: Sometimes, it takes time to update the DNS record. Be patient.

Creating your PythonAnywhere account, opening bash console, and running two commands. That’s all you have to do to make your website live on the internet. Isn’t it so simple?

The good thing about PythonAnywhere is that you will have full control of your server. You can take the backup of your Django website without any hassle.

After doing research and trying multiple hosting platforms, this is the PythonAnywhere is the simplest and most reliable platform. I’m using it to host more than 10 websites now. If you have any questions, you can ask me in the comment section below.

Python Interview Questions eBook

DjangoPythonAnywhere
Aniruddha Chaudhari
I am complete Python Nut, love Linux and vim as an editor. I hold a Master of Computer Science from NIT Trichy. I dabble in C/C++, Java too. I keep sharing my coding knowledge and my own experience on CSEstack.org portal.

Your name can also be listed here. Got a tip? Submit it here to become an CSEstack author.

Leave a Reply Cancel reply

Prerequisite for Django

Learn Python Basics

Django Tutorials

Why Django?

Django- Create Your First Project

Django- Adding CSS/Static Files

Django- Use/Load Static Files

Django- Create Form

Django- Create Input-Tags

Django- Display Message on Form Submit

Django- MultipleChoiceField in Form

Django- Read Model Data (order_by)

Django- Read First/Last Queryset Object

Django- Update Model Field

Django- Signals

Django- Create TextField in Form

Django- Add Model to Admin Site

Django- Customize Admin Site

Django- Understanding Model User

Django- Registration/Signup Form

Django- Form Layout with Widget-Tweaks

Django- OneToOneField in Model

Django- Foreign Key & Reverse Lookup

Django- Custom Template Filters

Django- Interactive Shell

Django- Social Login

Django- Deploy and Host [FREE] 🔥

© 2022 – CSEstack.org. All Rights Reserved.

  • Home
  • Subscribe
  • Contribute Us
    • Share Your Interview Experience
  • Contact Us
  • About
    • About CSEstack
    • Campus Ambassador
  • Forum & Discus
  • Tools for Geek
  • LeaderBoard