Skip to main content

Use Django Models in any Python Web Framework

Project description

# DJ Models

Use the Django ORM in any Python web framework.

## Install

pip3 install djmodels

## Getting Started

Create an app directory for your models and settings (DB connection details).

mkdir app
touch app/{,,}

Add your database settings to the settings module. See Django's docs on this for more info.

'default': {
'ENGINE': 'djmodels.db.backends.postgresql',
'NAME': 'postgres',
'USER': 'postgres',
'PASSWORD': 'mysecretpassword',
'HOST': '',
'PORT': '5432',



Add a model to `app/`

from djmodels.db import models

class Person(models.Model):
name = models.CharField()
age = models.PositiveIntegerField()

Export your settings module

export DJMODELS_SETTINGS_MODULE=app.settings

Create migrations

$ djmodels-admin makemigrations app
# Migrations for 'app':
# - Create model Person

Run Migrate

$ djmodels-admin migrate app
# Operations to perform:
# Apply all migrations: app
# Running migrations:
# Applying app.0001_initial... OK

Import the model into any webframework and make queries. For example, Flask.


from flask import Flask
from app.models import Person
app = Flask(__name__)

def get_random_person():
person = Person.objects.order_by('?').first()
return '{}'.format(


## Gotchas

- Make sure to set


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for DJModels, version 0.0.3
Filename, size File type Python version Upload date Hashes
Filename, size DJModels-0.0.3-py3-none-any.whl (3.4 MB) File type Wheel Python version py3 Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page