Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/they4kman/flango
Flask-like interface for Django
https://github.com/they4kman/flango
django flask
Last synced: 3 months ago
JSON representation
Flask-like interface for Django
- Host: GitHub
- URL: https://github.com/they4kman/flango
- Owner: theY4Kman
- Created: 2017-02-11T18:24:52.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-04-26T13:25:08.000Z (over 6 years ago)
- Last Synced: 2024-09-15T00:27:24.761Z (4 months ago)
- Topics: django, flask
- Language: Python
- Size: 15.6 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# flango!
Do you like the niceties of Flask, but have to use Django for some reason? Are you a lunatic?
If you answered yes twice, this library is for you!
Supports Python 2.6 to 3.7, and Django 1.8+
# Quickstart
Install package.
```bash
pip install flango
```Create Flango app, add it to your urls.
```python
# urls.py
from flango import Flangoapp = Flango(__name__)
@app.route('/')
def index(pk):
from django.contrib.auth.models import User
return User.objects.get(pk=pk).first_nameurlpatterns = app.urlpatterns
```# Benefits
- Access current request anywhere
```python
from django import forms
from flango import request
class MyForm(forms.Form):
def save(self):
instance = super(MyForm, self).save(commit=False)
instance.user = request.user
instance.save()
return instance
```- Declare your routes alongside your views
```python
from flango import render_template
from myapp import app
@app.route('/about')
def about():
return render_template('about.html')
```- Typed variable parts
```python
from flango import render_template
from myapp import app
@app.route('/map//')
def map(lat, long):
assert isinstance(lat, float)
assert isinstance(long, float)
return render_template('map.html', lat=lat, long=long)
```- Return response content, status code, and headers directly from views
```python
from myapp import app
@app.route('/ok')
def ok():
return 'ok'
@app.route('/idk')
def idk():
return 'idk', 404
@app.route('/wat')
def wat():
return 'wat', 400, {'Content-Type': 'text/wat'}
```- Save precious PEP-8 space when building URLs
```python
from django.db import models
from flango import url_for
class MyModel(models.Model):
def get_invitation_link(self, friend_name):
return url_for('my-model-invite', id=self.id, friend_name=friend_name)
```# Using `flango.request` with regular Django views
Flango wraps your view functions to provide the `request` object globally. When your form or other code which accesses `flango.request` is called from a regular Django view, it will fail.
To fix this, add Flango's `global_request_middleware` to your `settings.MIDDLEWARE`:
```python
# settings.py
MIDDLEWARE = (
'flango.global_request_middleware',
# ...
)
```For best results, place it at the top of the list. This allows you to use `flango.request` in other middlewares.