我正在编辑django allauth,以便在设备移动时更改模板,我已尝试使用django-mobile
request.mobile
和request.GET.get('mobile')
同时使用&#39 ;工作网址是/accounts/signup/?mobile=true
这是我到目前为止所做的事情
class LoginView(RedirectAuthenticatedUserMixin,
AjaxCapableProcessFormViewMixin,
FormView):
form_class = LoginForm
template_name = "account/login.html"
success_url = None
redirect_field_name = "next"
def form_valid(self, form):
success_url = self.get_success_url()
return form.login(self.request, redirect_url=success_url)
def get_success_url(self):
# Explicitly passed ?next= URL takes precedence
ret = (get_next_redirect_url(self.request,
self.redirect_field_name)
or self.success_url)
return ret
def get_context_data(self, **kwargs):
ret = super(LoginView, self).get_context_data(**kwargs)
signup_url = passthrough_next_redirect_url(self.request,
reverse("account_signup"),
self.redirect_field_name)
redirect_field_value = self.request.REQUEST \
.get(self.redirect_field_name)
if self.request.GET.get('mobile'):
self.template_name = 'mobile/sign_up.html'
ret.update({"signup_url": signup_url,
"site": Site.objects.get_current(),
"redirect_field_name": self.redirect_field_name,
"redirect_field_value": redirect_field_value})
return ret
答案 0 :(得分:0)
这里有冗余空格符号:
redirect_field_value = self.request.REQUEST \
.get(self.redirect_field_name) # ^ space should be removed!