mirror of
https://github.com/jazzband/django-dbtemplates.git
synced 2026-03-16 22:20:28 +00:00
Merge 58f24d2173 into 10e7de2eda
This commit is contained in:
commit
271cea22a1
10 changed files with 194 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -12,3 +12,4 @@ docs/_build
|
|||
*.egg/
|
||||
.coverage
|
||||
coverage.xml
|
||||
db.sqlite3
|
||||
|
|
|
|||
|
|
@ -17,3 +17,6 @@
|
|||
color: #999;
|
||||
}
|
||||
|
||||
.CodeMirror-wrapping {
|
||||
width: 85%;
|
||||
}
|
||||
|
|
|
|||
26
example/README.md
Normal file
26
example/README.md
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
# Example project
|
||||
|
||||
This example Django app helps us develop the library, so we can quickly set it up for testing.
|
||||
|
||||
## Usage
|
||||
|
||||
Using uv you can run the following commands to have a working application
|
||||
|
||||
```bash
|
||||
# create the virtualenv
|
||||
uv venv --python 3.13
|
||||
# activate it
|
||||
source .venv/bin/activate
|
||||
# install Django
|
||||
uv pip install -r requirements.txt
|
||||
# install the library as editable
|
||||
uv pip install -e ../.
|
||||
# run migrations to create the base database
|
||||
python manage.py migrate
|
||||
# create a superuser test account
|
||||
python manage.py createsuperuser
|
||||
# start the dev server
|
||||
python manage.py runserver
|
||||
```
|
||||
|
||||
After this is done you can navigate to http://localhost:8000/admin/ and login with your account, create a DB Template called `db-index.html` and then go to http://localhost:8000 to see it.
|
||||
0
example/example/__init__.py
Normal file
0
example/example/__init__.py
Normal file
109
example/example/settings.py
Normal file
109
example/example/settings.py
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
from pathlib import Path
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = "django-insecure-r^0hv0s#-%%jt!a7v1e7_#s+(@**(wn1n59iauee3e4t4e0&7r"
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = ["*"]
|
||||
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
"django.contrib.admin",
|
||||
"django.contrib.auth",
|
||||
"django.contrib.contenttypes",
|
||||
"django.contrib.sessions",
|
||||
"django.contrib.sites",
|
||||
"django.contrib.messages",
|
||||
"django.contrib.staticfiles",
|
||||
"dbtemplates",
|
||||
"example",
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
"django.middleware.security.SecurityMiddleware",
|
||||
"django.contrib.sessions.middleware.SessionMiddleware",
|
||||
"django.middleware.common.CommonMiddleware",
|
||||
"django.middleware.csrf.CsrfViewMiddleware",
|
||||
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
||||
"django.contrib.messages.middleware.MessageMiddleware",
|
||||
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
||||
]
|
||||
|
||||
ROOT_URLCONF = "example.urls"
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
||||
"DIRS": [BASE_DIR / "example" / "templates"],
|
||||
"APP_DIRS": False,
|
||||
"OPTIONS": {
|
||||
"context_processors": [
|
||||
"django.template.context_processors.debug",
|
||||
"django.template.context_processors.request",
|
||||
"django.contrib.auth.context_processors.auth",
|
||||
"django.contrib.messages.context_processors.messages",
|
||||
],
|
||||
"loaders": [
|
||||
"django.template.loaders.filesystem.Loader",
|
||||
"django.template.loaders.app_directories.Loader",
|
||||
"dbtemplates.loader.Loader",
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = "example.wsgi.application"
|
||||
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
"default": {
|
||||
"ENGINE": "django.db.backends.sqlite3",
|
||||
"NAME": BASE_DIR / "db.sqlite3",
|
||||
}
|
||||
}
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators
|
||||
|
||||
AUTH_PASSWORD_VALIDATORS = []
|
||||
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/4.2/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = "en-us"
|
||||
|
||||
TIME_ZONE = "UTC"
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/4.2/howto/static-files/
|
||||
|
||||
STATIC_URL = "static/"
|
||||
|
||||
# Default primary key field type
|
||||
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
|
||||
|
||||
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
||||
|
||||
SITE_ID = 1
|
||||
|
||||
DBTEMPLATES_USE_CODEMIRROR = True
|
||||
9
example/example/urls.py
Normal file
9
example/example/urls.py
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
from django.contrib import admin
|
||||
from django.urls import path
|
||||
|
||||
from .views import index
|
||||
|
||||
urlpatterns = [
|
||||
path("", index),
|
||||
path("admin/", admin.site.urls),
|
||||
]
|
||||
5
example/example/views.py
Normal file
5
example/example/views.py
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
from django.shortcuts import render
|
||||
|
||||
|
||||
def index(request):
|
||||
return render(request, "db-index.html")
|
||||
16
example/example/wsgi.py
Normal file
16
example/example/wsgi.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
"""
|
||||
WSGI config for example project.
|
||||
|
||||
It exposes the WSGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.settings")
|
||||
|
||||
application = get_wsgi_application()
|
||||
23
example/manage.py
Executable file
23
example/manage.py
Executable file
|
|
@ -0,0 +1,23 @@
|
|||
#!/usr/bin/env python
|
||||
"""Django's command-line utility for administrative tasks."""
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
"""Run administrative tasks."""
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.settings")
|
||||
try:
|
||||
from django.core.management import execute_from_command_line
|
||||
except ImportError as exc:
|
||||
raise ImportError(
|
||||
"Couldn't import Django. Are you sure it's installed and "
|
||||
"available on your PYTHONPATH environment variable? Did you "
|
||||
"forget to activate a virtual environment?"
|
||||
) from exc
|
||||
execute_from_command_line(sys.argv)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
2
example/requirements.txt
Normal file
2
example/requirements.txt
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
django==5.2.9
|
||||
django-dbtemplate
|
||||
Loading…
Reference in a new issue