How do I require HTTPS for this Django view?

2024/10/4 15:38:33
(r'^login/?$','django.contrib.auth.views.login',{'template_name':'login.html', 'authentication_form':CustomAuthenticationForm}),

How do I add HTTPS required to this? I usually have a decorator for it..

But in this case I can't apply it.

def secure_required(view_func):"""Decorator makes sure URL is accessed over https."""def _wrapped_view_func(request, *args, **kwargs):if not request.is_secure():if getattr(settings, 'HTTPS_SUPPORT', True):request_url = request.build_absolute_uri(request.get_full_path())secure_url = request_url.replace('http://', 'https://')return HttpResponseRedirect(secure_url)return view_func(request, *args, **kwargs)return _wrapped_view_func
Answer

I believe you can wrap the function in this manner:

from django.contrib.auth.views import login
from <<wherever>> import secure_requiredurlpatterns = patterns('',(r'^login/?$',secure_required(login),{'template_name':'login.html', 'authentication_form':CustomAuthenticationForm}),
)
https://en.xdnf.cn/q/70590.html

Related Q&A

How many times a number appears in a numpy array

I need to find a way to count how many times each number from 0 to 9 appears in a random matrix created using np.random.randint()import numpy as np p = int(input("Length of matrix: ")) m = np…

python: How to remove values from 2 lists based on whats in 1 list

I have 2 lists of numbers, one called xVar and the other called yVar. I will use these 2 elements to plot X and Y values on a graph. They both have the same number of elements. Normally, I would jus…

merge two dataframe columns into 1 in pandas

I have 2 columns in my data frame and I need to merge it into 1 single columnIndex A Index B 0 A 0 NAN 1 NAN 1 D 2 B 2 …

Upsample and Interpolate a NumPy Array

I have an array, something like:array = np.arange(0,4,1).reshape(2,2)> [[0 12 3]]I want to both upsample this array as well as interpolate the resulting values. I know that a good way to upsample an…

How to extract text from table in image?

I have data which in a structured table image. The data is like below:I tried to extract the text from this image using this code:import pytesseract from PIL import Imagevalue=Image.open("data/pic…

numpy.savetxt tuple index out of range?

Im trying to write a few lines into a text file, and heres the code I used:import numpy as np# Generate some test data data = np.arange(0.0,1000.0,50.0)with file(test.txt, w) as outfile: outfile.w…

Retrieve list of USB items using Python

How can I retrieve the items plugged into the computer through USB using python? Ive searched around on here and found some old examples which dont appear to work anymore as they are over 5 years old.…

History across ipdb sessions

This question has been asked before, but I couldnt find a good answer. So, I am trying to ask again.I would like my ipdb to remember commands across sessions. Right now, it can pull up commands execute…

Python Distributed Computing (works)

Im using an old thread to post new code which attempts to solve the same problem. What constitutes a secure pickle? this?sock.pyfrom socket import socket from socket import AF_INET from socket import…

Django - Stream request from external site as received

How can Django be used to fetch data from an external API, triggered by a user request, and stream it directly back in the request cycle without (or with progressive/minimal) memory usage?BackgroundAs…