A minimal Django web application configured for deployment on AWS Elastic Beanstalk.
This project demonstrates a basic Django setup with a simple homepage response, WSGI/ASGI configuration, dependency management, and Elastic Beanstalk deployment configuration.
When the application runs successfully, the homepage displays:
Hello from Elastic Beanstalk Django App!
The purpose of this repository is to demonstrate how to create and deploy a basic Django application using AWS Elastic Beanstalk.
This project covers:
- Basic Django project structure
- Django URL routing
- Django view creation
- WSGI application configuration
- ASGI application configuration
- Python dependency management
- AWS Elastic Beanstalk deployment setup
- Static files configuration
- Python
- Django 5.0.2
- Gunicorn
- AWS Elastic Beanstalk
- GitHub
DjangoFolder/
│
├── .ebextensions/
│ └── django.config
│
├── mysite/
│ ├── __init__.py
│ ├── asgi.py
│ ├── settings.py
│ ├── urls.py
│ ├── views.py
│ └── wsgi.py
│
├── application.py
├── manage.py
├── requirements.txt
└── README.md
This file exposes the Django WSGI application for AWS Elastic Beanstalk.
from mysite.wsgi import applicationElastic Beanstalk uses this file to locate the Django application object.
This is Django's command-line utility file. It is used to run development commands such as starting the local server, checking the project, and managing Django tasks.
Example:
python manage.py runserverThis file lists the Python packages required to run the project.
Current dependencies:
Django==5.0.2
gunicorn
Note: The current repository version may show these dependencies on one line. For best practice, keep each dependency on its own line.
Correct format:
Django==5.0.2
gunicorn
This file configures AWS Elastic Beanstalk to use the correct WSGI path.
The WSGI path is:
application:application
This means:
- The first
applicationrefers to the root-levelapplication.pyfile. - The second
applicationrefers to the imported WSGI application object.
This file contains the main Django project configuration.
Important settings include:
SECRET_KEY = 'replace-me'
DEBUG = True
ALLOWED_HOSTS = ['*']
INSTALLED_APPS = [
'django.contrib.contenttypes',
'django.contrib.staticfiles'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware'
]
ROOT_URLCONF = 'mysite.urls'
WSGI_APPLICATION = 'mysite.wsgi.application'
STATIC_URL = '/static/'
STATIC_ROOT = BASE_DIR / 'staticfiles'This file defines the URL routes for the project.
The root URL / is connected to the home view:
urlpatterns = [
path('', views.home),
]This file contains the homepage view.
The home view returns a simple HTTP response:
from django.http import HttpResponse
def home(request):
return HttpResponse("Hello from Elastic Beanstalk Django App!")This file creates the WSGI application used by production web servers and AWS Elastic Beanstalk.
application = get_wsgi_application()This file creates the ASGI application for asynchronous server support.
application = get_asgi_application()Follow these steps to run the project on your computer.
git clone https://github.com/iamwaqarjaved/DjangoFolder.git
cd DjangoFolderpython -m venv .venvOn Windows:
.venv\Scripts\activateOn macOS or Linux:
source .venv/bin/activatepip install --upgrade pip
pip install -r requirements.txtpython manage.py runserverOpen this URL in your browser:
http://127.0.0.1:8000/
Expected output:
Hello from Elastic Beanstalk Django App!
This project includes Elastic Beanstalk configuration through the .ebextensions folder.
Before deployment, confirm that these files exist:
application.py
requirements.txt
.ebextensions/django.config
mysite/settings.py
mysite/wsgi.py
The Elastic Beanstalk WSGI path should be:
application:application
In the AWS Elastic Beanstalk console:
- Create a new application.
- Choose Python as the platform.
- Upload the project source code.
- Deploy the environment.
- Open the Elastic Beanstalk environment URL.
After deployment, open the Elastic Beanstalk URL in your browser.
You should see:
Hello from Elastic Beanstalk Django App!
Run local server:
python manage.py runserverCheck Django project configuration:
python manage.py checkInstall dependencies:
pip install -r requirements.txtCollect static files:
python manage.py collectstaticCreate a new Django app:
python manage.py startapp appnameA typical workflow for making changes:
git clone https://github.com/iamwaqarjaved/DjangoFolder.git
cd DjangoFolder
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python manage.py runserverAfter editing files:
git add .
git commit -m "Update Django project"
git push origin mainMake sure requirements.txt is formatted correctly:
Django==5.0.2
gunicorn
Then run:
pip install --upgrade pip
pip install -r requirements.txtCheck that the virtual environment is activated and dependencies are installed:
pip install -r requirements.txt
python manage.py runserverCheck the WSGI path in .ebextensions/django.config:
application:application
Also confirm that application.py exists in the project root.
Check mysite/urls.py and mysite/views.py.
The root URL should point to the home view:
urlpatterns = [
path('', views.home),
]The view should return an HTTP response:
def home(request):
return HttpResponse("Hello from Elastic Beanstalk Django App!")The current project is configured for learning and development.
Before using it in production, update the following settings:
DEBUG = False
ALLOWED_HOSTS = ['your-domain.com']
SECRET_KEY = 'your-secure-secret-key'Recommended production improvements:
- Store
SECRET_KEYin an environment variable. - Set
DEBUG = False. - Restrict
ALLOWED_HOSTS. - Add secure middleware settings.
- Configure a production database if needed.
- Run
collectstaticbefore deployment. - Avoid committing sensitive values to GitHub.
Several files in this repository may appear on one line. For readability and proper Python/YAML formatting, make sure these files use correct line breaks and indentation:
manage.py
application.py
requirements.txt
.ebextensions/django.config
mysite/settings.py
mysite/urls.py
mysite/views.py
mysite/wsgi.py
mysite/asgi.py
Possible future improvements include:
- Add HTML templates
- Add CSS styling
- Add a database model
- Enable Django admin
- Add unit tests
- Add environment variable support
- Add production-ready settings
- Add a
buildspec.ymlfile for AWS CodeBuild - Add CI/CD deployment automation
- Add custom domain support
Waqar Javed
GitHub: iamwaqarjaved
This project is created for academic and learning purposes.