Python Tip 1: Accessing localhost Django webserver over the Internet

We use Django development webserver to test our application on localhost.

We can start the development webserver with below command:

Now one problem we face with this approach is that we can access/browse the project over the browser only in the local network to which our system is connected.

What if you want to show your project to someone at another location, in another city over the Internet?

How would you generate a public URL for your localhost webserver?

 

For such situations, there is one software available. ngrok.

How to use it:

– Download the ngrok from its download page .

ngrok download

–  Follow the documentation to unzip the downloaded content and to add the authentication token.

– Go to your project directory and activate your virtual environment.

–  Now start your Django development server at port lets say 8080.

– You can access your project on localhost:8080. We will generate a public URL for this localhost URL by creating a tunnel using ngrok.

– Go to the directory where you unzipped ngrok and run below command.

– You will see something like this:

ngrok tunnel

– Now you can access your project over the public address http://9f134cf4.ngrok.io  .

–  You can access the web interface on http://127.0.0.1:4040 to see which URL got how many hits.

Public URL for localhost Django project

 

You can host your Django App for free on PythonAnyWhere server.

How to backup database periodically on PythonAnyWhere server

You can host your Django app effortlessly on PythonAnyWhere server. If you are using the database in your app then it is strongly recommended to take backup of database to avoid loss of data.

This PythonAnyWhere article explain the process to take sql dump. We will extend the same article to take database backup periodically and delete the old files.

Continue reading “How to backup database periodically on PythonAnyWhere server”

How to setup Django app on EC2 instance (AWS) – Part 2

In the previous part of article we completed the environment setup to host the Django app on EC2 instance of AWS.

How to setup Django app on EC2 instance (AWS) – Part 1.

Hosting Django Apps on PythonAnyWhere server for free. Step by step guide.

In this article we will start from where we left in last part.

Database initialisation:

Activate the virtual environment.
source venv/bin/activate

Make migrations.
python manage.py makemigrations

If you get a message –  No changes detected then make sure migration files from development environment are not present. If still same message is received, mention the name of app with makemigration command.

Continue reading “How to setup Django app on EC2 instance (AWS) – Part 2”

How to setup Django app on EC2 instance (AWS)

Recently I hosted Django project on EC2 instance of AWS. I find the process very difficult due to multiple reasons which we will see in article.

Hosting on PythonAnyWhere is cake walk as compare to hosting on EC2 instance. And pricing is also almost same.

Since I have gone through the process, I am sharing the step by step approach to host Django application on EC2 instance.

 

Steps to host Django app on EC2:

Login:

Create the account and get the .pem file.

Place the file in on your system and change the permission on that file to 644.  chmod 644 aws_key.pem

Login to system from terminal.  ssh -i aws_key.pem ec2_user@ec2-232-999-89-1.compute-1.amazonaws.com

Now you are into your home directory. Running pwd  will give you  /home/ec2-user .

Continue reading “How to setup Django app on EC2 instance (AWS)”

How to host django app on pythonanywhere for free

So you developed a course project which you need to host somewhere so that everyone can access it.
Or you are working on some personal project and want to host it so that test users can test it.

What do you do in such scenario? You look for best hosting service provider. Right?
So what is best option to host your django app?

We tried multiple hosting providers and found out that best choice for a django app is pythonanywhere.com. why? Find out below.

Continue reading “How to host django app on pythonanywhere for free”