Mar-14-2019, 02:00 PM
I’ve discovered a ‘hack’ to correct the issue. I committed and pushed my changes up to my GitHub repo for those curious enough to try it out yourself.
My problem now is that I don’t really understand why it works. Here I will explain what I do know and then my ask would be for you people to fill in the gaps in my explanation. First I share my working code.
Here is my views.py which includes the relevant function I use:
I’m not sure why a conditional as it appears above is necessary.
Would someone here care to explain, if you can?
My problem now is that I don’t really understand why it works. Here I will explain what I do know and then my ask would be for you people to fill in the gaps in my explanation. First I share my working code.
Here is my views.py which includes the relevant function I use:
from django.http import HttpResponse from django.shortcuts import render def home(request): if 'ccEntry' in request.GET: number = request.GET['ccEntry'] redacted_num = 'xxxx xxxx xxxx {}'.format(number[-4:]) return render(request, 'home.html', {'number':number, 'redacted_num':redacted_num}) else: return render(request, 'home.html')Here is my lucid, cerebral explanation of the above Python code in plain English: At line 4 I am defining the
home
function. Then there is a conditional referring to the ‘ccEntry’ string inside the template. If ccEntry is present in the GET request, then a number
variable is declared based on the user input on the webpage. Then a redacted_num
variable is declared which will appear as a string (‘xxxx xxxx xxxx ’ with the last 4 characters lopped off (the slice)). If all of the above is in order, then the render function will be returned:- with the standard request,
- with reference to the home.html template,
- along with a dictionary with a ‘number’ string matching up with the
number
variable. Ditto for the redact_num.
I’m not sure why a conditional as it appears above is necessary.
Would someone here care to explain, if you can?