DEV Community

loading...
Cover image for Host Your Django Project in pythonanywhere Free

Host Your Django Project in pythonanywhere Free

mh_shifat profile image 5hfT ・2 min read

PythonAnywhere is an online integrated development environment and web hosting service based on the Python programming language.
You can host your pet projects here which is free.

Let's start :

  • Go to PythonAnywhere
  • Create account and login
  • Go to consoles
  • Select bash console
  • Create virtual environment for python
mkvirtualenv --python=python3.8 envname
Enter fullscreen mode Exit fullscreen mode
  • Your environment will be activated and in bash you will see the envname in parenthesis
  • Install django
pip install -U django==3.0.3
Enter fullscreen mode Exit fullscreen mode
  • check django path
which django-admin.py
Enter fullscreen mode Exit fullscreen mode
  • install necessary packages
pip instal xyz
Enter fullscreen mode Exit fullscreen mode
  • Clone git repo
git clone repo.git
Enter fullscreen mode Exit fullscreen mode

Note : You should have a git repo of the project or web application

  • Go to dashboard of pythonanywhere.com and go to Web
  • Select create new web app
    • next
    • select manual configuration
    • next next done !
  • Here you will see the url for your project click and you will see hello world page which is default for python

    Config WebApp :

  • setvirtualenv path which you will find in console using
which django-admin.py
Enter fullscreen mode Exit fullscreen mode
  • set source code as /home/username/projectname
  • static files

    • set /static/admin/ as /home/username/.virtualenvs/blog/lib/python3.8/site-packages/django/contrib/admin/static/admin
    • set /static/ as your project static folder path as mine is /home/jspw/shifat.com/blog/static
  • set Virtualenv dir as /home/username/.virtualenvs/env_name

  • Edit WSGI configuration file as the file given below

import os
import sys
## assuming your django settings file is at '/home/jspw/mysite/mysite/settings.py'
## and your manage.py is is at '/home/jspw/mysite/manage.py'
path = '/home/jspw/mysite'  #path of your project
if path not in sys.path:
    sys.path.append(path)
os.chdir(path)
os.environ.setdefault('DJANGO_SETTINGS_MODULE', "food_menu_project.settings")  #projectname.settings
import django

django.setup()
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
Enter fullscreen mode Exit fullscreen mode
  • Done ! Clik on the reload in the webapp page then go to the website url and boom!!!

Note : Check settings.py file and you have allowed your host url.

Discussion (0)

Forem Open with the Forem app