Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A Python/Django with MySQL template, for quick development setup in Crafting Sandbox.

License

Notifications You must be signed in to change notification settings

crafting-dev/template-python-django

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

7 Commits

Repository files navigation

Python/Django with MySQL template for Crafting Sandbox

This is a Python/Django with MySQL template, configured for quick development setup in Crafting Sandbox.

Specifications

This template defines a single /ping route:

urlpatterns = [
 path('ping', views.ping),
]

whose view is defined as:

def ping(request):
 ping = request.GET.get('ping')
 if ping == "":
 ping = 'To ping, or not to ping; that is the question.'
 pong = {
 'ping': ping,
 'received_at': datetime.utcnow()
 }
 return JsonResponse(pong)

This action receives a query string, and responds with the param string and the current time. For example:

$ curl --request GET 'localhost:3000/ping?ping=hello'
{"ping": "hello", "received_at": "XXXX-XX-XXXXX:XX:XX.XXX"}

Template is configured with MySQL, and mysite/settings.py contains the connection configuration.

DATABASES = {
 'default': {
 'ENGINE': 'django.db.backends.mysql',
 'HOST': environ.get('MYSQL_SERVICE_HOST'),
 'PORT': environ.get('MYSQL_SERVICE_PORT'),
 'NAME': 'XXX',
 'USER': 'XXX',
 'PASSWORD': 'XXX'
 }
}

To run the app:

uv run manage.py runserver 0.0.0.0:3000

App Definition

The following App Definition was used to create this template:

endpoints:
- name: api
 http:
 routes:
 - pathPrefix: "/"
 backend:
 target: python-django
 port: api
 authProxy:
 disabled: true
workspaces:
- name: python-django
 description: Template backend using Python/Django
 ports:
 - name: api
 port: 3000
 protocol: HTTP/TCP
 checkouts:
 - path: backend
 repo:
 git: https://github.com/crafting-dev/template-python-django
dependencies:
- name: mysql
 serviceType: mysql
 version: '8'
 properties:
 database: superhero
 password: batman
 username: brucewayne

About

A Python/Django with MySQL template, for quick development setup in Crafting Sandbox.

Resources

License

Stars

Watchers

Forks

Contributors 3

AltStyle によって変換されたページ (->オリジナル) /