简体   繁体   中英

Django Middleware Login Required

I am trying to implement site wide login restriction based on information found here :

I have created the login_required_middleware.py in:

/home/user/projects/test/test/

I have added the following to my MIDDLEWARE_CLASSES in settings.py

'test.LoginRequiredMiddleware',

When I refresh in my browser, I receive the error:

A server error occurred.  Please contact the administrator.

Where do I go next?

This is happening because it's not finding your middleware. Make sure your middleware is in the python path of your project.

for example if the name of your middleware is login_required_middleware.py you should put it in the directory of manage.py or in any subdirectory.

then in settings.py in the MIDDLEWARE_CLASSES you should call it like

'login_required_middleware.LoginRequiredMiddleware'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM