How Deploy Django Web App Project to production using Python anywhere - Free Hosting

00:13:50
https://www.youtube.com/watch?v=-5Ft9WOWPGQ

Summary

TLDRThis tutorial guides users through creating a GitHub repository and deploying a Python project on PythonAnywhere. It starts with setting up a new repository, initializing it, and pushing changes using a series of Git commands. It also includes steps for creating and excluding files, such as a .gitignore file for untracked files. The deployment process on PythonAnywhere involves setting up a virtual environment, installing Django, creating an app, and configuring the WSGI file. The tutorial highlights common errors and their solutions, such as setting allowed hosts and running migrations to avoid database issues.

Takeaways

  • πŸ“ Creating a GitHub repository requires setting visibility and initializing it with Git commands.
  • πŸ”’ Use a .gitignore file to exclude specific files from being tracked.
  • 🌐 Deploying on PythonAnywhere involves creating a virtual environment and setting up the app paths.
  • πŸ”§ Proper setup of the WSGI file is crucial for app deployment.
  • πŸš€ Run 'git push' to upload project changes to GitHub after configuration.
  • πŸ› οΈ Address allowed host errors by editing the settings.py file.
  • βš™οΈ Handle database migration errors by executing necessary migration commands.
  • πŸ”„ Switching branches and adding origins is necessary for correct commit.
  • πŸ” Verify the virtual environment setup with proper paths in PythonAnywhere.
  • πŸ“ˆ Debugging requires setting proper secret keys and ensuring secure configurations.

Timeline

  • 00:00:00 - 00:05:00

    The video walks through the process of creating a new repository on GitHub. It outlines the steps involved in initializing a repository, including the creation of a .gitignore file to exclude unnecessary files, such as database and cache files, from being pushed to the repository. It then details the sequence of commands needed to add files, commit changes, switch branches, and set the origin for the repository. Finally, the video explains how to authenticate and push the changes to the GitHub account, ending with a verification of the commit on the GitHub webpage.

  • 00:05:00 - 00:13:50

    The next segment covers deploying a repository to PythonAnywhere, beginning with cloning the GitHub repository into a PythonAnywhere environment. Viewers learn how to create a virtual environment and install necessary packages like Django. It further explains setting up a web app on PythonAnywhere, configuring paths, and editing WSGI files. There is emphasis on setting the allowed host in settings.py for deployment. The video finishes with instructions on applying migrations to the database on PythonAnywhere and verifying the deployed site's functionality. It highlights debugging tips and the importance of configuration changes in production environments.

Mind Map

Video Q&A

  • How do I initialize a new Git repository?

    Use the command 'git init' after creating the repository.

  • What commands are needed to push changes to GitHub?

    The sequence typically involves 'git add', 'git commit', and 'git push', with necessary configuration of repository origin.

  • How can I exclude files from being pushed to GitHub?

    Create a .gitignore file and list the files or directories you wish to exclude.

  • How do you set up a virtual environment in PythonAnywhere?

    Use the 'mkvirtualenv' command with a specified Python version path to create a virtual environment.

  • What do you need to do after creating an app on PythonAnywhere?

    Provide paths for the source code and virtual environment, then configure the WSGI file.

View more video summaries

Get instant access to free YouTube video summaries powered by AI!
Subtitles
en
Auto Scroll:
  • 00:00:00
    foreign
  • 00:00:00
    [Music]
  • 00:00:06
    here we will be creating a repository
  • 00:00:08
    I'm giving a name as a short URL I'm
  • 00:00:11
    keeping a description then repository
  • 00:00:14
    visibility as a public then I'm not
  • 00:00:16
    checking any kind any check boxes here
  • 00:00:19
    so I will just go and create a project
  • 00:00:21
    just click on the create a repository
  • 00:00:24
    this will create a repository for us on
  • 00:00:26
    our GitHub account
  • 00:00:28
    so this is the commands that we need to
  • 00:00:30
    run uh basically on our project there
  • 00:00:33
    are two types of commands firstly so you
  • 00:00:35
    can initialize the repository from
  • 00:00:37
    beginning or you can push the existing
  • 00:00:38
    text repository to one GitHub account
  • 00:00:40
    inside the project just copy paste the
  • 00:00:43
    First Command that is so creating the
  • 00:00:45
    Eco short URL to redmi.amd this will
  • 00:00:48
    create a file and that will write down
  • 00:00:49
    the short URL inside it after that one
  • 00:00:51
    just initialize the repository getting
  • 00:00:54
    it this will initialize the gate inside
  • 00:00:57
    our project after that one just create a
  • 00:00:59
    gate ignore file uh this should be a
  • 00:01:02
    start with a dot inside that we will be
  • 00:01:04
    excluding the project folder or the
  • 00:01:06
    files that we don't want to push to our
  • 00:01:08
    our GitHub account like a SQL database
  • 00:01:12
    then URL project that is our
  • 00:01:14
    virtual environment then after that one
  • 00:01:16
    the migrations files and the py cache
  • 00:01:18
    files this these are the important files
  • 00:01:20
    that we need to exclude
  • 00:01:22
    after excluding this file just go to our
  • 00:01:24
    account and just copy paste the second
  • 00:01:26
    command that is third command sorry git
  • 00:01:28
    add redmi.amd and with that one uh we
  • 00:01:31
    will just copy pasting that in that one
  • 00:01:33
    inside our terminal and that will add to
  • 00:01:35
    our tracked file so after uh with that
  • 00:01:38
    one also we also need to add all the
  • 00:01:41
    files from the project to track to track
  • 00:01:44
    it down so uh just add a DOT operator
  • 00:01:47
    there and that will add all the files to
  • 00:01:50
    that
  • 00:01:51
    now after that one just write down the
  • 00:01:52
    commit message and just hit enter
  • 00:01:55
    that will give a message to our first
  • 00:01:58
    comments after that one just switch to
  • 00:02:00
    our main branch because we were on the
  • 00:02:02
    master Branch previously
  • 00:02:04
    after that one just add the origin of
  • 00:02:06
    the project that is the kit uh origin
  • 00:02:09
    where this project needs to be pushed
  • 00:02:11
    let's after that one just copy paste
  • 00:02:13
    another command and that will push all
  • 00:02:15
    the project to our GitHub before that
  • 00:02:18
    one you need to authenticate yourself
  • 00:02:19
    that you are the person who has have the
  • 00:02:21
    authenticity for this
  • 00:02:24
    edible
  • 00:02:25
    add the username password click login
  • 00:02:28
    and this it will just push all the data
  • 00:02:31
    to our main GitHub account
  • 00:02:33
    so now just visit the GitHub account and
  • 00:02:35
    you can see we have the projects uh data
  • 00:02:39
    on our repository just click on the code
  • 00:02:41
    or refresh the page that will show the
  • 00:02:43
    project
  • 00:02:44
    you can say the first commitment is a
  • 00:02:46
    message that we provided and uh
  • 00:02:55
    after pushing the project to the GitHub
  • 00:02:57
    now let's move on to the python anywhere
  • 00:02:59
    so here I have the deploying
  • 00:03:01
    documentation for python anywhere here
  • 00:03:03
    you can see there are four step involved
  • 00:03:05
    inside here that is uploading the
  • 00:03:06
    project to the python anywhere then
  • 00:03:08
    setting up the version environment and
  • 00:03:09
    installing the chunk other dependency
  • 00:03:11
    then setting up the or creating a new
  • 00:03:13
    app inside the python anywhere with that
  • 00:03:15
    one setting up the static files so you
  • 00:03:18
    can see the First Command we will have
  • 00:03:20
    to run is like taking the work
  • 00:03:22
    GitHub project to our this python animal
  • 00:03:25
    terminal or you can say on machine
  • 00:03:28
    so you can do that one here as well with
  • 00:03:31
    that one also here are the some of the
  • 00:03:33
    commands for creating a version
  • 00:03:35
    environment then setting up the
  • 00:03:36
    requirements like installing the
  • 00:03:39
    requirement.txt file and all these
  • 00:03:41
    things
  • 00:03:41
    so let's go and uh copy our first
  • 00:03:47
    file
  • 00:03:53
    just copy the https URL from GitHub and
  • 00:03:57
    just come to the python animal click on
  • 00:04:00
    bash inside the console here you can it
  • 00:04:03
    will start a new terminal for us
  • 00:04:05
    it will take some little bit time to get
  • 00:04:07
    set up on initial
  • 00:04:18
    okay let's do first of all the ALS to
  • 00:04:21
    see anything what is here so you can see
  • 00:04:23
    redmi docs txt file is already there
  • 00:04:26
    let's clone the water repository we have
  • 00:04:30
    uploaded with this one with this command
  • 00:04:33
    that's gig clone repository uh git https
  • 00:04:36
    name this will create a new folder that
  • 00:04:38
    is shorty button so now let's try to
  • 00:04:41
    install our virtual environment first of
  • 00:04:43
    all because that is a necessary
  • 00:04:47
    here I am using a next command that is
  • 00:04:48
    make a virtual environment my virtual
  • 00:04:50
    environment is the name of the virtual
  • 00:04:51
    environment with the python path of that
  • 00:04:55
    and I am removing a 10 with the
  • 00:04:58
    8 so this should be creative virtual
  • 00:05:00
    environment for us so this will install
  • 00:05:02
    all the requirements for the python that
  • 00:05:04
    is set up to pay for Bill
  • 00:05:07
    once this has been done you can see
  • 00:05:09
    there is a path of the virtual
  • 00:05:11
    environment as well
  • 00:05:13
    now let's install the PIP install uh
  • 00:05:15
    sorry let's install the Django here with
  • 00:05:18
    the pp install Django this will install
  • 00:05:19
    the latest version of the Django to our
  • 00:05:21
    terminal once that has been installed
  • 00:05:24
    now we don't have any requirement.txt
  • 00:05:26
    file here so we don't have to run this
  • 00:05:28
    next command that this requirement uh
  • 00:05:31
    installing the dependencies from that
  • 00:05:32
    but in the larger project we will have
  • 00:05:35
    to install that one as well so in our
  • 00:05:37
    case it's not there so we are going to
  • 00:05:39
    ignore it
  • 00:05:40
    so now let's uh after this one we will
  • 00:05:43
    have to create a app manually inside our
  • 00:05:46
    python anywhere
  • 00:05:47
    to create an app after creating app we
  • 00:05:49
    will have to set up some of the things
  • 00:05:51
    for the same that is a folder path then
  • 00:05:53
    virtual environment path and then wha
  • 00:05:55
    file path
  • 00:05:56
    now let's face it to the dashboard our
  • 00:05:58
    dashboard then inside here just click on
  • 00:06:01
    the open Vapor tab
  • 00:06:04
    that will open a window and just click
  • 00:06:07
    on add a new web app
  • 00:06:09
    so we are not using any premium account
  • 00:06:11
    here we will be going with the existing
  • 00:06:13
    Administration that is my username with
  • 00:06:15
    the python anywhere
  • 00:06:17
    click on next choose a manual
  • 00:06:19
    configuration then click on also next
  • 00:06:23
    here it's showing that uh we need to
  • 00:06:25
    edit the whji file for this manual
  • 00:06:28
    configuration
  • 00:06:29
    just click on next
  • 00:06:34
    okay our app is has been created
  • 00:06:36
    successfully so you can see we need to
  • 00:06:38
    provide the source code path then
  • 00:06:40
    version environment path
  • 00:06:42
    and also if there any status files you
  • 00:06:44
    can also provide a static file URL as
  • 00:06:46
    well so now let's visit our URL you can
  • 00:06:50
    see our web is working fine
  • 00:06:52
    so now uh
  • 00:06:54
    let's go to the version environment
  • 00:06:56
    where we can provide the name so you can
  • 00:06:58
    see uh virtual environment path should
  • 00:07:00
    be like your username then app name then
  • 00:07:03
    virtual environment path to find out
  • 00:07:06
    that one what we can do is like we could
  • 00:07:08
    go with again uh files
  • 00:07:11
    uh here you can see virtual environments
  • 00:07:13
    uh third link just click on that one
  • 00:07:16
    and after clicking on that one now you
  • 00:07:19
    can see there is a my virtual
  • 00:07:20
    environment as well
  • 00:07:32
    copy that path just paste it inside the
  • 00:07:34
    virtual environment path click on OK so
  • 00:07:37
    this will have the path of the virtual
  • 00:07:39
    environment
  • 00:07:40
    after that one let's provide the source
  • 00:07:42
    code path I guess so
  • 00:07:45
    yeah we should provide a source code so
  • 00:07:47
    source code which should be a working
  • 00:07:49
    directory or
  • 00:07:53
    so the working directory for our project
  • 00:07:55
    is like I will go to Administration then
  • 00:07:58
    short URL
  • 00:08:05
    click on it then short URL again that is
  • 00:08:09
    the app our project name
  • 00:08:11
    and here is heaven we have our source
  • 00:08:13
    code
  • 00:08:18
    also remember that one source code file
  • 00:08:21
    uh path should be where your manage.pify
  • 00:08:23
    file lives in so I'm just copying this
  • 00:08:27
    path because there is a manager of your
  • 00:08:28
    file inside here
  • 00:08:30
    and providing that path to the source
  • 00:08:32
    code
  • 00:08:32
    click on OK
  • 00:08:35
    this should be okay to go now the final
  • 00:08:38
    part for this project is to edit whj
  • 00:08:40
    file
  • 00:08:42
    foreign
  • 00:08:45
    you know to provide some of the things
  • 00:08:47
    like here in the documentation you can
  • 00:08:49
    see we need to enable this part of the
  • 00:08:51
    Django where you are importing importing
  • 00:08:53
    OS system and the configuration so here
  • 00:08:57
    am I in my web app I'm just clicking on
  • 00:09:00
    that file name WJR configuration file
  • 00:09:02
    that will open a new tab
  • 00:09:06
    where there will be a this uh all the
  • 00:09:09
    HTML so what we need to do is like
  • 00:09:11
    remember we need to enable the Django
  • 00:09:12
    part and remove the existing whatever
  • 00:09:14
    the
  • 00:09:16
    part is there
  • 00:10:19
    remember my side will be the name of
  • 00:10:21
    your project so it should be
  • 00:10:24
    you can verify that one going to your
  • 00:10:27
    file path that is home at this
  • 00:10:29
    Administration then
  • 00:10:34
    name of the project once the test has
  • 00:10:36
    been that has been done just reload the
  • 00:10:37
    save the this file and reload the app
  • 00:10:40
    you can do by click on that button as
  • 00:10:42
    well
  • 00:10:58
    also go to the web app and also do to
  • 00:11:01
    refresh to refresh there as well so we
  • 00:11:04
    have the complete a refresh of the work
  • 00:11:06
    project so once that is written done you
  • 00:11:09
    can see there is a error that is
  • 00:11:10
    Administration python animal dot on is
  • 00:11:12
    need to be added to the allowed host
  • 00:11:14
    because we are we haven't added that one
  • 00:11:17
    to our device right now so I will go to
  • 00:11:19
    my GitHub account
  • 00:11:21
    and uh I will find out that setting.url
  • 00:11:24
    dot sorry setting.pure file and I will
  • 00:11:27
    directly going to edit here itself on
  • 00:11:29
    the gator power itself
  • 00:11:31
    so ins click on the edit
  • 00:11:36
    paste allow to instant allowed host and
  • 00:11:39
    save the file or commit the file to the
  • 00:11:40
    directly mailbox
  • 00:11:42
    we are keeping the debug true and the
  • 00:11:43
    secret key as insecure because this is
  • 00:11:46
    not going to get covered inside this
  • 00:11:47
    tutorial but in the future we you should
  • 00:11:50
    or if you are doing some uh major update
  • 00:11:53
    to our project you should change the
  • 00:11:55
    secret key and also the debug should be
  • 00:11:57
    a false on the production remember that
  • 00:11:59
    one that's setting
  • 00:12:00
    so once that has been done and we will
  • 00:12:02
    have to
  • 00:12:03
    take the new
  • 00:12:05
    version of our project with this uh this
  • 00:12:08
    on this console so I will just go to our
  • 00:12:11
    short URL directory
  • 00:12:13
    doing a city
  • 00:12:14
    and just do a get a git push sorry gate
  • 00:12:18
    pull
  • 00:12:19
    so that will bring out all the necessary
  • 00:12:21
    changes to our this terminal
  • 00:12:23
    after doing that one we will also going
  • 00:12:25
    to
  • 00:12:27
    refresh our page as well
  • 00:12:30
    just go to the app and reload our
  • 00:12:32
    administrator
  • 00:12:34
    project
  • 00:12:43
    it should now working but you can see we
  • 00:12:47
    haven't applied the migrations and them
  • 00:12:49
    so it will fail it will give us some
  • 00:12:51
    errors on the database level so you can
  • 00:12:53
    see the short URL app is not existing or
  • 00:12:56
    the operation is not allowed
  • 00:12:58
    so to do so we will going to run the
  • 00:13:00
    migration scope for whole project and
  • 00:13:03
    for app as well so that will solve this
  • 00:13:06
    error as well
  • 00:13:14
    now if I enter the again you can see the
  • 00:13:18
    site is working fine we have the URL if
  • 00:13:20
    I click on it it opens the necessary
  • 00:13:23
    page as well
  • 00:13:26
    so this is it for this Pro whole project
  • 00:13:29
    or a whole tutorial for deploying the
  • 00:13:31
    your projector
  • 00:13:33
    python animal.com
  • 00:13:35
    so if you have any kind of a queries
  • 00:13:37
    regarding the same do comment it out so
  • 00:13:39
    I could reach a reach out immediately
  • 00:13:41
    and uh looking forward thank you so much
Tags
  • GitHub
  • PythonAnywhere
  • Deployment
  • Git
  • Django
  • WSGI
  • Virtual Environment
  • Repository
  • Python