Skip to content

Loading…

get_context_data key misses return as "None" and possibly rendered in template #49

Merged
merged 1 commit into from

2 participants

@bennylope

Both the empty string and None evaluate to not true, but None will be displayed as "None" in a template. Setting an empty string default obviates the need for template conditionals to display or not display the next value.

This:

<input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}">

Will, with default values, render as this:

<input type="hidden" name="next" value="None">

Which results in a NoReverseMatch error because the given URL path is "None". The solution is a template conditional:

{% if redirect_field_value %}
<input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}">
{% endif %}

But this shouldn't be necessary. Since the empty string also evaluate to False this shouldn't be expected to break backwards compatibility for existing code.

@bennylope bennylope Gets empty string as default for redirect_field_name
Both the empty string and None evaluate to not true, but None will be
displayed as "None" in a template. This obviates the need for template
conditionals to display or not display the next value.
7c3f886
@brosner brosner merged commit 1e14254 into pinax:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 20, 2012
  1. @bennylope

    Gets empty string as default for redirect_field_name

    bennylope committed
    Both the empty string and None evaluate to not true, but None will be
    displayed as "None" in a template. This obviates the need for template
    conditionals to display or not display the next value.
This page is out of date. Refresh to see the latest.
Showing with 6 additions and 6 deletions.
  1. +6 −6 account/views.py
View
12 account/views.py
@@ -76,7 +76,7 @@ def get_context_data(self, **kwargs):
redirect_field_name = self.get_redirect_field_name()
ctx.update({
"redirect_field_name": redirect_field_name,
- "redirect_field_value": self.request.REQUEST.get(redirect_field_name),
+ "redirect_field_value": self.request.REQUEST.get(redirect_field_name, ""),
})
return ctx
@@ -238,7 +238,7 @@ def get_context_data(self, **kwargs):
redirect_field_name = self.get_redirect_field_name()
ctx.update({
"redirect_field_name": redirect_field_name,
- "redirect_field_value": self.request.REQUEST.get(redirect_field_name),
+ "redirect_field_value": self.request.REQUEST.get(redirect_field_name, ""),
})
return ctx
@@ -299,7 +299,7 @@ def get_context_data(self, **kwargs):
redirect_field_name = self.get_redirect_field_name()
ctx.update({
"redirect_field_name": redirect_field_name,
- "redirect_field_value": self.request.REQUEST.get(redirect_field_name),
+ "redirect_field_value": self.request.REQUEST.get(redirect_field_name, ""),
})
return ctx
@@ -435,7 +435,7 @@ def get_context_data(self, **kwargs):
redirect_field_name = self.get_redirect_field_name()
ctx.update({
"redirect_field_name": redirect_field_name,
- "redirect_field_value": self.request.REQUEST.get(redirect_field_name),
+ "redirect_field_value": self.request.REQUEST.get(redirect_field_name, ""),
})
return ctx
@@ -538,7 +538,7 @@ def get_context_data(self, **kwargs):
"uidb36": self.kwargs["uidb36"],
"token": self.kwargs["token"],
"redirect_field_name": redirect_field_name,
- "redirect_field_value": self.request.REQUEST.get(redirect_field_name),
+ "redirect_field_value": self.request.REQUEST.get(redirect_field_name, ""),
})
return ctx
@@ -642,7 +642,7 @@ def get_context_data(self, **kwargs):
redirect_field_name = self.get_redirect_field_name()
ctx.update({
"redirect_field_name": redirect_field_name,
- "redirect_field_value": self.request.REQUEST.get(redirect_field_name),
+ "redirect_field_value": self.request.REQUEST.get(redirect_field_name, ""),
})
return ctx
Something went wrong with that request. Please try again.