Giter VIP home page Giter VIP logo

mini-django's Introduction

Run on Google Cloud

Mini-Django

An entire django app in a single file. Updated from here to use Django trunk. Works with Django 1.11, 2.x, and 3.x.

Quick Start

Clone https://github.com/readevalprint/mini-django

$ docker build . -t mini-django
$ docker run -p 8000:8000 -v `pwd`:/app mini-django

and go to http://localhost:8000/Foo. You can change the code in mini_django.py and the server will automatically reload as soon as you save your changes.

Dependencies

Install

  1. Clone this repo
  2. (optional) Create a virtualenv virtualenv -p python3 venv and activate it using source venv/bin/activate.
  3. Install Python dependencies pip install -r requirements.txt
  4. You can now run the three sample servers using one of the commands below:
    • PYTHONPATH=. django-admin.py runserver 0.0.0.0:8000 --settings=pico_django
    • python mini_django.py runserver
    • python mini_api.py runserver

pico

This started off to see what the absolutely smallest requirements needed to run a Django project. Run the pico_django.py with:

$ PYTHONPATH=. django-admin.py runserver 0.0.0.0:8000 --settings=pico_django

You can then go to http://localhost:8000 to see the running server.

mini

Soon pico needed a little more spice, so it got some template loading and then because I'm lazy I made the new version directly runnable. Run the mini_django.py with

$ python mini_django.py runserver

and go to http://localhost:8000/Foo

api

Often I need to use django-rest-framework for a simple one-off task, thankfully, mini_django can be adapted quite easily into mini_api.py

$ python mini_api.py runserver

and go to http://localhost:8000

Production

You can also run these Django projects in production-like mode using a WSGI server like uWSGI or gunicorn.

uWSGI

First run pip install uwsgi to install the uWSGI package (requires build tools). You can then start the server using:

$ uwsgi --http :8000 -M --pythonpath=. \
    --env DJANGO_SETTINGS_MODULE=mini_django \
    -w "django.core.wsgi:get_wsgi_application()"

Replace mini_django with pico_django or mini_api to run the other projects.

gunicorn

First install gunicorn using pip install gunicorn, then start the server using:

$ gunicorn --bind 0.0.0.0:8000 \
    --env DJANGO_SETTINGS_MODULE=mini_django \
    "django.core.wsgi:get_wsgi_application()"

Replace mini_django with pico_django or mini_api to run the other projects.

Disclaimer

Note the above "production" examples are only given as POC to show the code works and not recommended for use in a real production environment. You'd need to think about number of WSGI workers, using NGINX to serve static files, and other such.

License

As-is. Public Domain. Don't blame me.

Author

Tim Watts ([email protected]) @readevalprint

Contributors

Ivan Savov ([email protected]) @minireference

mini-django's People

Contributors

ivanistheone avatar readevalprint avatar vstoykov 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  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  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  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mini-django's Issues

Small changes to make it work with latest Django 3.1.1

I'm using a file similar to mini_django.py in production (via WSGI via gunicorn) and recently tested it with latest version of Django 3.1.1.

We can't pass **locals() to configure anymore since there is some new validation in Django 3: all settings must be ALL_CAPS.

Here is a screenshot of the changes I had to make for it to work:

works with lates Django 3 1 1

Note SECRET_KEY and ROOT_URLCONF must be defined in main file AND in the SETTINGS dict.

If any of this looks useful and Django 3 support sounds useful, I can open a PR.

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.