Coder Social home page Coder Social logo

louxsdon / django-breeze Goto Github PK

View Code? Open in Web Editor NEW
32.0 1.0 2.0 400 KB

Django Breeze provides a minimal and simple starting point for building a Django application with Inertia and Vite with minimal or no configuration. Styled with Tailwind CSS.

License: MIT License

Python 54.92% JavaScript 16.90% CSS 0.84% HTML 6.11% TypeScript 13.34% Vue 7.90%
django inertia react vite vue breeze

django-breeze's Introduction

django-breeze-logo

Django Breeze

Introduction

Django Breeze provides a minimal and simple starting point for building a Django application with Inertia and Vite.js with minimal or no configuration. Styled with Tailwind CSS.

Inertia helps build single-page apps, without building an API. Create modern single-page React, Vue, and Svelte apps using classic server-side routing. Works with any backend. Documentation for Inertia can be found on the Intertia website.

Setup and Installation

Before installing the packages, ensure you are in your project's virtual environment.

  1. Install the django-breeze package.
pip install django-breeze
  1. Create a new django project if you haven't created one already.
django-breeze startproject myproject

Add the django_breeze to your INSTALLED_APPS in settings.py

INSTALLED_APPS = [
  #..............
  'django_breeze',
  #..............
]

Generate Project Files

Generate your frontend project files with django-breeze, use --typescript option for usage with TypeScript.

React

django-breeze create-app react

Vue 3

django-breeze create-app vue3

After generating your frontend project files, you should see src directory with other relevant files in the root of your django project.

Install the frontend packages

Run this command to install packages for the frontend.

npm install

# or

yarn

Start the Servers

Run the following commands to start your development servers.

  1. Vite server
npm run dev
  1. Django server
python manage.py runserver

Now visit your django host address at e.g http://127.0.0.1:8000/

django-breeze-success-setup screen

Now you're all set!

Usage

Responses

Render Inertia responses is simple, you can either use the provided inertia render function or, for the most common use case, the inertia decorator. The render function accepts four arguments, the first is your request object. The second is the name of the component you want to render from within your pages directory (without extension). The third argument is a dict of props that should be provided to your components. The final argument is template_data, for any variables you want to provide to your template, but this is much less common.

# views.py

from inertia import render
from .models import Event

def index(request):
  return render(request, 'Event/Index', props={
    'events': Event.objects.all()
  })

Or use the simpler decorator for the most common use cases

# views.py

from inertia import inertia
from .models import Event

@inertia('Event/Index')
def index(request):
  return {
    'events': Event.objects.all(),
  }

For more information on the usage, refer to inertia-django Docs.

Production

In production, you must do the following:

  1. In the settings.py
DEBUG = FALSE
  1. Run below command to build your frontend files
npm run build
# or
yarn build
  1. Run below django command to collect static files.
python -m manage.py collectstatic

Settings

Although, djang breeze comes with minimal or no configuration but here are some of the default settings it comes with out of the box.

Django Settings

# settings.py

STATIC_ROOT = "static"

 DJANGO_BREEZE = {
        "INERTIA": {
            "LAYOUT": "index.html",
            "SSR_URL": "http://localhost:13714",
            "SSR_ENABLED": False,
        },
        "DJANGO_VITE": {
            "DEV_MODE": True, # vite dev mode, default based on django DEBUG
            "SERVER_PROTOCOL": "http",
            "DEV_SERVER_HOST": "localhost",
            "DEV_SERVER_PORT": 5173,
            "WS_CLIENT_URL": "@vite/client",
            "ASSETS_PATH": "static/dist", # vite build asset path
            "STATIC_URL_PREFIX": "",
        }
 }

Settings for Inertia Django is under INERTIA and Django Vite is DJANGO_VITE. You can find more explaination of the settings on their repos

Note: All settings are joined with underscore to match how their developers defined them e.g inertia settings is INERTIA_LAYOUT and django vite is DJANGO_VITE_DEV_MODE which has been done automatically by django breeze so you just use the DJANGO_BREEZE settings format in your settings.py file.

Thank you

A very big thanks to the following people for their work done:

License

Django Breeze is open-sourced software licensed under the MIT license.

django-breeze's People

Contributors

dependabot[bot] avatar louxsdon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

bheny oboynitro

django-breeze's Issues

install error

is this package on pypi?

I am getting this when I try to install:

(venv) (base) โžœ  src git:(main) pip install django-breeze
ERROR: Ignored the following versions that require a different python version: 0.1.0 Requires-Python >=3.10,<4.0; 0.1.1 Requires-Python >=3.10,<4.0; 0.1.2 Requires-Python >=3.10,<4.0; 0.1.3 Requires-Python >=3.10,<4.0; 0.1.4 Requires-Python >=3.10,<4.0; 0.1.5 Requires-Python >=3.10,<4.0; 0.1.6 Requires-Python >=3.10,<4.0; 0.2.0 Requires-Python >=3.10,<4.0; 0.3.0 Requires-Python >=3.10,<4.0; 0.3.1 Requires-Python >=3.10,<4.0; 1.0.0 Requires-Python >=3.10,<4.0
ERROR: Could not find a version that satisfies the requirement django-breeze (from versions: none)
ERROR: No matching distribution found for django-breeze

pip -V
pip 23.1.2

Cannot read properties of undefined (reading 'default')

Describe the bug

createInertiaApp.ts:34 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'default')
    at createInertiaApp.ts:34:93
    at async j2 (createInertiaApp.ts:38:18)

To Reproduce
Steps to reproduce the behavior:

  1. git clone [email protected]:krunaldodiya/django-breeze-demo.git
  2. npm install
  3. python manage.py runserver

Expected behavior
It should show hompage without any warnings

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • Pop OS / linux
  • google chrome

Additional context
Add any other context about the problem here.
Screenshot from 2023-12-01 15-09-35

STATICFILES_DIRS warnings

WARNINGS:
?: (staticfiles.W004) The directory '/Users/dwiga/Playground/dwilab/silvertech/src/public' in the STATICFILES_DIRS setting does not exist.
?: (staticfiles.W004) The directory 'static/dist' in the STATICFILES_DIRS setting does not exist.

To Reproduce
appeared soon after running the app python manage.py runserver

Expected behavior
No issues appeared

Desktop (please complete the following information):

  • OS: Mac OS X

How to fix the issue? something I need to do?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.