I'm a a beginner developer for Python and Javascript...
Javascript, HTML, CSS, Python...
This is my project where I have made a heroku app and deployed all the things with the help of github. Go and Visit Now
Don't worry Github is here.
Follow the following steps to host your site fro free.
-
Install django and pipenv using
pip install pipenv pip install django pipenv install django [For Creating Virtual Environment and Pipfile & Pipfile.lock]
-
Open the folder where you want to save your project and type cmd in the place of the folder's path and run this command
django-admin startproject <projectname>
-
After constructing your site add Procfile and type
web: gunicorn <projectname>.wsgi
#ignore commands.txt that is a file temporarily I have created
-
Install gunicorn and whitenoise through pipenv as well as pip
pip/pipenv install gunicorn pip/pipenv install whitenoise
-
Then in your settings.py add this MIDDLEWARE
'whitenoise.middleware.WhiteNoiseMiddleware',
-
Now you need to add STATIC_ROOT Path in settings.py to tell where to look for static files e.g, css, js, etc.
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
-
Now add new “static” folder inside root directory of your project, if you don’t have and then run following command to collect all inbuilt static files related to django-admin
python/python3 manage.py collectstatic
-
Now add requirements.txt file to your root directory. So, that heroku could install all the required packages that they need to run this app on their server.
pip freeze > requirements.txt
-
Now you need to install git If you haven’t installed it. Go and Just install Git from its official website and install it:
Download Git From Here: Click Here
Then go to github and create a new repository and push your code by running the following commands
git init
git add README.md (Optional)
git add .
git commit -m "first commit"
git branch -M main
git remote add orgin <github repository link.git>
git push -u origin main
- Create an app on heroku
-
Once you’ve selected name for your app then add your app_domain inside your ALLOWED_HOST in settings.py
ALLOWED_HOSTS = [ '127.0.0.1', '<projectname>.herokuapp.com', ]
-
Now again, commit and push these changes to your github
> git add . > git commit -m "Allowed Hosts" > git push -u origin main
-
Now you need connect that github repository to your heroku app. Where your configured django project is available.
and click on connect after finding the repository
- Now scroll down and there you will see option Enable Automatic Deploys, click on it to enable this feature.
And Now whenever you will make and new changes in your repository then it will automatically fetch your changes and then will apply those changes to deployed app.