小编sta*_*hit的帖子

Django 为 WebView 返回带有 TokenAuthentication 的视图

我正在尝试创建一个 flutter 应用程序,它将使用 webview 显示来自我的 Django 应用程序的经过身份验证的数据。

涉及步骤:

  1. Flutter 应用发送身份验证请求
  2. Django 验证用户凭据(用户 ID 和密码)并返回 authtoken
  3. Flutter 然后通过 webview 将请求发送到 url(需要登录)。

我想使用此令牌在 webapp 中登录用户并返回 webview。如果 url 不需要身份验证,它就像一个魅力。当 url 需要身份验证时,我被重定向到登录页面,我希望用户使用已在步骤 1 中获得的令牌身份验证绕过该页面

这是我的 Django 视图。

class QuizTake(FormView):
    permission_classes = (IsAuthenticated,)
    form_class = QuestionForm
    template_name = 'question.html'
    result_template_name = 'result.html'
    single_complete_template_name = 'single_complete.html'
    login_template_name='login.html'

      
    def dispatch(self, request, *args, **kwargs):
        self.quiz = get_object_or_404(Quiz, url=self.kwargs['quiz_name'])
        print(self.kwargs['quiz_name'])
        
        """
        Authenticate if the request has token authentication
        """

        if self.quiz.draft and not request.user.has_perm('quiz.change_quiz'):
            raise PermissionDenied

        try:
            self.logged_in_user = …
Run Code Online (Sandbox Code Playgroud)

python django django-authentication django-rest-framework django-rest-knox

6
推荐指数
1
解决办法
183
查看次数

Flutter google 登录为 google 验证 django 社交身份验证

我正在创建一个使用 google 登录的 flutter android 应用程序。登录后,我会收到 accesstoken 和 idtoken。我想使用此令牌来验证我的后端,该后端使用 django 社交身份验证和

  1. 如果用户已经注册,则登录并返回authoken,或者
  2. 注册用户,登录并返回用户 ID 和 authtoken。

这可能吗 ?如果是这样,请在线建议任何文件,或者请解释我应该如何处理这个问题。

django django-socialauth firebase-authentication google-signin flutter

5
推荐指数
1
解决办法
2610
查看次数

Django 需要 2 个值在 for 循环中解包;得到 1

我已经寻找过其他答案,但无法让这个答案发挥作用。我有一个带有存储字典的Sitting字段的模型user_answers

{"437": "1574", "319": "hi", "383": "1428", "424": "1528", "203": "785"}
Run Code Online (Sandbox Code Playgroud)

当我做

 {% for key, value in sitting %}
    <p> {{key}}--{{value}} </p>
    <p> {{question.id}}--{{answer.id}} </p>
        {% ifequal key question.id %}
            {% ifequal  value answer.id %}
                <li class="list-group-item quiz-answers" >
                <span><label for="id_answers_0"><input type="radio" name="answers_{{question.id}}" value="{{answer.id}}" style="margin-right:10px;" id="{{answer.id}}" selected required>
                {{answer.content}}  </label>  </span></li>  
            {% else %}    
            <li class="list-group-item quiz-answers" >
                <span><label for="id_answers_0"><input type="radio" name="answers_{{question.id}}" value="{{answer.id}}" style="margin-right:10px;" id="{{answer.id}}"  required>
                {{answer.content}}  </label>  </span></li>   
            {% endifequal %}
        {% endifequal %}
{% endfor …
Run Code Online (Sandbox Code Playgroud)

python django dictionary django-templates

2
推荐指数
1
解决办法
4521
查看次数