This template provides a streamlined setup for integrating a React + Tailwind app (built with Vite) into a Django project. It's designed to be used as a Django app, offering a modern front-end development experience within a robust Python web framework.
- React for building user interfaces
- Tailwind CSS for rapid styling
- Vite for fast builds and hot module replacement
- Seamless integration with Django
- Python 3.x
- Node.js and Yarn
- Django
-
Ensure you have an existing Django project. Your initial file structure should look like this:
/ ├── project/ │ ├── __init__.py │ ├── asgi.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py └── manage.py
-
Clone this template repository:
git clone https://github.com/an4s911/reactapp-django-starter.git yourappname
After cloning, your file structure will update to:
/ ├── project/ │ ├── asgi.py │ ├── __init__.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py ├── manage.py └── yourappname/ ├── src/ │ ├── App.jsx │ ├── index.css │ └── main.jsx ├── templates/ │ └── base.html ├── __init__.py ├── apps.py ├── views.py ├── index.html ├── package.json ├── vite.config.js ├── tailwind.config.js ├── eslint.config.js ├── postcss.config.js ├── yarn.lock └── README.md
-
Update the app name in
yourappname/apps.py
:from django.apps import AppConfig class FrontConfig(AppConfig): default_auto_field = "django.db.models.BigAutoField" name = "yourappname"
-
Install dependencies:
cd yourappname yarn install
-
Start the Vite build process:
yarn refresh
Note: For development purposes only, you can run
yarn dev
to start the Vite development server. This cannot be used alongside Django. -
Add the app to your Django project in
project/settings.py
:INSTALLED_APPS = [ # ... other apps "yourappname", ]
-
Configure static files in
project/settings.py
:STATICFILES_DIRS = [ BASE_DIR / "yourappname/dist", ]
-
Update
project/urls.py
to include your app's views:from django.urls import path from yourappname import views urlpatterns = [ # ... other urls path("", views.index, name="index"), ]
-
Start the Django development server:
python manage.py runserver 0.0.0.0:8000
-
Visit
http://localhost:8000
in your browser to see your app in action!
- Make changes to your React components in the
yourappname/src
directory. - The Vite build process (
yarn refresh
) will automatically rebuild your app. - Refresh your browser to see the changes.
Before deploying to production:
- Run
yarn build
to create an optimized production build. - Ensure
DEBUG = False
in your Django settings. - Configure your web server to serve static files from the
yourappname/dist
directory.
- If you encounter any issues with static files, run
python manage.py collectstatic
. - Make sure your Django
STATIC_URL
andSTATIC_ROOT
setting is correctly configured.
Contributions are welcome! Please feel free to submit a Pull Request.