Build a Web App using Django
Django is an exceptional choice for building a full-stack Web App in 2024. It stands apart from typical hype cycles and is known for its maturity and stability. Combined with tailwindcss it truly is one of our favourite frameworks.
The django-app
template gives you a full-stack Web App built with Django and Postgres
Setup
Create a virtual environment
Install phidata
Install docker
Install docker desktop to run your app locally
Export your OpenAI key
You can get an API key from here.
Create your codebase
Create your codebase using the django-app
template pre-configured with Django and PostgreSQL
This will create a folder named django-app
with the following structure:
Set OpenAI Key
Set your OPENAI_API_KEY
as an environment variable. You can get one from OpenAI.
Local Web App
Your codebase comes with a pre-configured Django application connected to a Postgres database. Run it using:
Press Enter to confirm and give a few minutes for the image to download (only the first time). Verify container status and view logs on the docker dashboard.
View your Django App
Open localhost:8000 to view the Django App running locally.
Django Admin
Open localhost:8000/admin to view the Django admin site. Create an admin user by running:
Log in to the admin panel:
Build your Web App
The Django Tutorials are a great place to learn about Django, play around and update your Web App to your use case. Here's how to create a simple chat application:
1. Create a new django app
Read more about django apps here
2. Register the chat app
Update the 'app/settings.py' file and register the chat
3. Create views for the chat app
Update the chat/views.py
file to
4. Configure URLs
Create a file named urls.py
in the chat folder:
Update the app/urls.py
file to:
5. Create templates
Create the HTML templates for the chat interface in the chat/templates/chat
folder.
6. Open Django App
Open localhost:8000/chat/ to view the LLM chat app.
If needed, restart the django server using phi ws restart dev:docker:app -y
Delete local resources
Play around and stop the workspace using:
Next
Congratulations on running your Django App locally. Next Steps:
- Run your Django App on AWS
- Read how to update workspace settings
- Read how to create a git repository for your workspace
- Read how to manage the development application
- Read how to format and validate your code
- Read how to add python libraries
- Chat with us on discord
Was this page helpful?