I have built my first Django App! It is built to help my business track inventory. As such, I would not like it to be publicly available.
我构建了我的第一个Django应用!它是用来帮助我的业务跟踪库存的。因此,我不希望公开它。
Maybe someday I will set up multiple user accounts, etc, but for now I really just need a basic password gate to get it up and running.
也许有一天我会建立多个用户帐户,等等,但是现在我真的需要一个基本的密码门来启动和运行它。
Does anyone have any middleware that works for this? All the solutions that I am finding are pretty old and they do not seem to work with the latest version of Django.
有没有人有适合这个的中间件?我找到的所有解决方案都很旧,而且它们似乎不能与最新版本的Django兼容。
2 个解决方案
#1
1
If you just need a single username/password couple, handling it directly via HTTP authentication in your webserver configuration will be the easiest way to achieve this. The benefits of this approach are:
如果您只需要一个用户名/密码对,那么通过webserver配置中的HTTP身份验证直接处理它将是实现这一点的最简单的方法。这种方法的好处是:
- You can set it up in 5 minutes: example with nginx, example with apache
- 您可以在5分钟内设置它:以nginx为例,以apache为例
- You don't have to write code you'll delete later
- 您不必编写稍后要删除的代码
- It will protect all your website, including static files, third-party apps, admin, etc.
- 它将保护你所有的网站,包括静态文件,第三方应用程序,管理员等。
#2
0
I found an answer that worked for me posted here:
我在这里找到了一个对我有用的答案:
@login_required for multiple views
@login_required为多个视图
Make sure the LOGIN_REQUIRED_URLS_EXCEPTIONS
path is correctly set to your login page.
确保正确地将login_required_urls_exception路径设置为登录页面。
#1
1
If you just need a single username/password couple, handling it directly via HTTP authentication in your webserver configuration will be the easiest way to achieve this. The benefits of this approach are:
如果您只需要一个用户名/密码对,那么通过webserver配置中的HTTP身份验证直接处理它将是实现这一点的最简单的方法。这种方法的好处是:
- You can set it up in 5 minutes: example with nginx, example with apache
- 您可以在5分钟内设置它:以nginx为例,以apache为例
- You don't have to write code you'll delete later
- 您不必编写稍后要删除的代码
- It will protect all your website, including static files, third-party apps, admin, etc.
- 它将保护你所有的网站,包括静态文件,第三方应用程序,管理员等。
#2
0
I found an answer that worked for me posted here:
我在这里找到了一个对我有用的答案:
@login_required for multiple views
@login_required为多个视图
Make sure the LOGIN_REQUIRED_URLS_EXCEPTIONS
path is correctly set to your login page.
确保正确地将login_required_urls_exception路径设置为登录页面。