0%

Django Deployment

Django Deployment

Demo on pythonanywhere

Option 1: Deploy to www.pythonanywhere.com

  1. Collect the requirement of you development environment
    In development environment

    1
    2
    ➜  git:(master) ✗ source activate dj
    (dj) ➜ git:(master) ✗ pip freeze > requirement.txt
  2. Upload code to Github

  3. Register an account on https://www.pythonanywhere.com

  4. Create a Web App

  5. Create Virtual Env:
    Open a Console

    1
    mkvirtualenv --python=python3.6 dj
  6. Download code and install required packages

    1
    2
    3
    4
    git clone https://github.com/chunkai-meng/QualityHats-Django.git
    cd QualityHats-Django
    pip install -r requirements.txt
    python manage.py migrate
  7. Create a supper user

    1
    2
    # if havn't created super user
    python manage.py createsuperuser <username>
  8. Back to Deshboard Page - Web - Add a new web app

    • Go to “web app setup” Page, input the following setting (change to your own)
      • Virtualenv: /home/hustmck/.virtualenvs/myproj
      • Source code: /home/hustmck/QualityHats-Django
    • Edit WSGI configuration file:/var/www/hustmck_pythonanywhere_com_wsgi.py
      • delete the Hello World code
      • Edit the Django code block as below
        1
        2
        3
        4
        5
        6
        7
        8
        9
        10
        11
        12
        13
        14
        15
        16
        17
        18
        19
        20
        21
        22
        23
        24
        # +++++++++++ DJANGO +++++++++++
        # To use your own django app use code like this:
        import os
        import sys
        #
        ## assuming your django settings file is at '/home/hustmck/mysite/mysite/settings.py'
        ## and your manage.py is is at '/home/hustmck/mysite/manage.py'
        path = '/home/hustmck/QualityHats-Django'
        if path not in sys.path:
        sys.path.append(path)

        os.chdir(path)
        os.environ.setdefault("DJANGO_SETTINGS_MODULE","qualityhats.settings")

        import django
        django.setup()
        #os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
        #
        ## then, for django >=1.5:
        from django.core.wsgi import get_wsgi_application
        application = get_wsgi_application()
        ## or, for older django <=1.4
        #import django.core.handlers.wsgi
        #application = django.core.handlers.wsgi.WSGIHandler()
  9. Reload your app

  10. Open your URL (Open Dashboard - Web tab - the link is on the top)

Deploy to AWS

coming soon

Deploy to Heroku