Code Monkey home page Code Monkey logo

django-request-context's Introduction

django-request-context

Django middleware which provide request and g object. all of which are accessible everywhere, and thread isolation, just like used in flask.

Installing

Install and update using pip:

pip install django-request-context

Usage

  1. Add RequestContextMiddleware to MIDDLEWARE in settings.py
import django_request_context

MIDDLEWARE = [
   ...
   'django_request_context.RequestContextMiddleware',
   ...
   ] 
  1. You can get request and g objects anywhere in the project throughout the life cycle of the request. just import:
from django_request_context import request, g

why do you need this?

when your django project is big enough and the function call stack is deep. if your want to get request object in the bottom of the call stack, you need to transfer request as parameters layer-by-layer, this can help you get request directly. the request you import from django-request-context is readonly object, if your want to convey some message you can user g object, this is a writeable object. the behavior of the request and g objects is exactly the same as in the flask.

django-request-context's People

Contributors

schecterdamien avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

django-request-context's Issues

ObjExisted at / , request already exist, can't replace

On a fresh django 2.2 installation (python3) installing django-request-context according to instructions and launching homepage results in :

ObjExisted at / , request already exist, can't replace.

Attached below is also a screenshot of the error page. Thanks for looking into this!

Screen Shot 2019-07-28 at 19 19 56

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.