-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
1,678 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
{ | ||
"recommendations": ["batisteo.vscode-django", "HookyQR.beautify"] | ||
"recommendations": [ | ||
"batisteo.vscode-django", | ||
"esbenp.prettier-vscode", | ||
"hookyqr.beautify", | ||
"ms-python.vscode-pylance", | ||
"vue.volar" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# Inertia + Django + Vite + Vue minimal template | ||
|
||
A minimal, working template for Inertia + Django + Vite + Vue. | ||
|
||
## Technologies | ||
|
||
1. Inertia - powered by the official [Inertia.js Django Adapter](https://github.com/inertiajs/inertia-django) | ||
2. Django v4.1 | ||
3. Vite 3 - powered by [Django Vite](https://github.com/MrBin99/django-vite) | ||
4. Vue 3 | ||
5. TypeScript | ||
6. [WhiteNoise](https://whitenoise.evans.io/en/stable/index.html) - to serve static files | ||
|
||
## How to install & run | ||
|
||
1. Download the repo. You can either: | ||
|
||
a. Clone the repo (without the git history): | ||
|
||
```sh | ||
npx degit https://github.com/mujahidfa/inertia-django-vite-vue-minimal | ||
``` | ||
|
||
b. Or, create a repo based on this template via the [GitHub template generator](https://github.com/mujahidfa/inertia-django-vite-vue-minimal/generate). | ||
|
||
2. Install required Python packages. | ||
|
||
```sh | ||
# Create and activate a virtual environment | ||
python3 -m venv .venv | ||
source .venv/bin/activate | ||
|
||
# Install required Python packages | ||
pip install -r requirements.txt | ||
``` | ||
|
||
3. Install required Ncode.js packages. | ||
|
||
```sh | ||
npm install | ||
``` | ||
|
||
4. Run the Vite dev server: | ||
|
||
```sh | ||
npm run dev | ||
``` | ||
|
||
5. Run Django's default migrations: | ||
|
||
```sh | ||
python manage.py migrate | ||
``` | ||
|
||
6. Run the Django dev server (in a separate terminal): | ||
|
||
```sh | ||
python manage.py runserver | ||
``` | ||
|
||
## How to build for production | ||
|
||
1. Set `DEBUG=False` in [settings.py](./inertia_django_vite_vue_minimal/settings.py). | ||
|
||
```py | ||
# In settings.py | ||
... | ||
DEBUG=False | ||
... | ||
``` | ||
|
||
2. Build the JS/assets for production: | ||
|
||
```sh | ||
npm run build | ||
``` | ||
|
||
3. Run `collectstatic`: | ||
|
||
```sh | ||
rm -rf staticfiles/ | ||
python manage.py collectstatic | ||
``` | ||
|
||
4. Run the Django server: | ||
|
||
```sh | ||
python manage.py runserver | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import "vite/modulepreload-polyfill"; | ||
import { createApp, h } from "vue"; | ||
import { createInertiaApp } from "@inertiajs/inertia-vue3"; | ||
|
||
createInertiaApp({ | ||
resolve: (name) => import(`./pages/${name}.vue`), | ||
setup({ el, app, props, plugin }) { | ||
createApp({ render: () => h(app, props) }) | ||
.use(plugin) | ||
.mount(el); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<script setup lang="ts"> | ||
import { computed, ref } from "vue"; | ||
defineProps<{ | ||
pageName: string; | ||
}>(); | ||
const count = ref(0); | ||
function increment() { | ||
count.value++; | ||
} | ||
const double = computed(() => count.value * 2); | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<h1 class="title">This is the {{ pageName }} page</h1> | ||
<button @click="increment">Add</button> | ||
<p>Count: {{ count }}</p> | ||
</div> | ||
</template> | ||
|
||
<style scoped> | ||
.title { | ||
color: green; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<script setup lang="ts"> | ||
import { computed, ref } from "vue"; | ||
defineProps<{ | ||
name: string; | ||
}>(); | ||
const count = ref(0); | ||
function increment() { | ||
count.value++; | ||
} | ||
const double = computed(() => count.value * 2); | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<h1 class="title">Hello {{ name }} from Inertia + Django + Vite + Vue!</h1> | ||
<button @click="increment">Add</button> | ||
<p>Count: {{ count }}</p> | ||
</div> | ||
</template> | ||
|
||
<style scoped> | ||
.title { | ||
color: green; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,20 @@ | ||
{% load django_vite %} | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Inertia + Django + Vite + Vue</title> | ||
|
||
{% vite_hmr_client %} | ||
{% vite_asset 'main.ts' %} | ||
|
||
<title>Inertia + Django + Vite + Vue minimal</title> | ||
</head> | ||
|
||
<body> | ||
<h1>Hello world!</h1> | ||
{% block inertia %}{% endblock %} | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ | |
|
||
urlpatterns = [ | ||
path("", views.index, name="index"), | ||
path("about", views.about, name="about"), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
from django.shortcuts import render | ||
from django.http import HttpRequest | ||
from inertia import render | ||
|
||
|
||
def index(request): | ||
return render(request, "index.html") | ||
return render(request, "Index", props={"name": "World"}) | ||
|
||
|
||
def about(request): | ||
return render(request, "About", props={"pageName": "About"}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.