Skip to content
A simple Hello, World! server app using Django.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs
mysite
.gitignore
LICENSE
Pipfile
Pipfile.lock
Procfile
README.md
requirements.txt

README.md

django-hello-world

Create from scratch

Requirements

Note: everything after homebrew should be installable via brew install python pipenv heroku-cli

# set up python dev environment
pipenv --three
pipenv install django django-heroku gunicorn
pipenv shell

# create the django project and app
django-admin startproject mysite
pushd mysite
python manage.py startapp myapp
popd

# create the Hello World! view
echo "from django.http import HttpResponse
def index(request):
    return HttpResponse('Hello, world!')" > mysite/myapp/views.py

# add the app route
echo "from django.urls import path
from . import views
urlpatterns = [
    path('', views.index, name='index'),
]" > mysite/myapp/urls.py

# add django_heroku settings
echo "import django_heroku
django_heroku.settings(locals())" >> mysite/mysite/settings.py

# update main project routes to direct towards app
sed -i '' 's/from django.urls import path/from django.urls import include, path/g' mysite/mysite/urls.py
sed -i '' 's/urlpatterns = \[/urlpatterns = \[\
    path(\'\', include(\'myapp.urls\')),/g' mysite/mysite/urls.py

# wrap dependencies for Heroku
pip freeze > requirements.txt

# create Procfile for Heroku
echo 'web: gunicorn --pythonpath mysite mysite.wsgi' > Procfile # Heroku expects the project to be at root level. `--pythyonpath` allows it to be in a specified subdirectory path.

# ignore the default sqlite database and python bytecode
echo "mysite/db.sqlite3
*.pyc" > .gitignore

Deployment

Local

pipenv shell
python mysite/manage.py runserver
open http://localhost:8000

Locally with Heroku:

heroku local
open http://localhost:5000

Deploying to Heroku

heroku create # make sure your ‘heroku’ git remote points to the correct app's git url, like if there was a previous one
git push heroku master
heroku open

References

Note: References preserved as PDFs in docs/.

Contribute

Issues and pull requests are welcome!

If this project helped you, please consider leaving a tip 🤗

Do you need help with a project? I'm currently available for hire or contract..

You can’t perform that action at this time.