2012-01-26 27 views
2

我無法爲我的django項目集成jquery mobile。特別是登錄功能似乎不能與jquery mobile(JQM)一起使用。 JQM使用ajax來處理郵件請求,我想阻止。在這個網站上http://blog.vrplumber.com/index.php?/archives/2511-Miscellaneous-jQuery-Mobile-+-Django-tips.html如何防止jquery mobile在django中使用ajax處理post請求

我讀,它可以防止JQM做那加

數據JSON =「假」

,但我在哪裏可以補充一點?在模板中還是在視圖中?我嘗試了不同的變化,但沒有效果。

這裏是我的登錄視圖:

def login(request):   
    if request.method == 'POST': 
     username = request.POST['u'] 
     password = request.POST['p'] 
     user = authenticate(username=username, password=password) 
     if user is not None: 
      if user.is_active: 
       auth_login(request, user) 
       msg.append("Hello %s your login was successful"% username) 
     return HttpResponseRedirect('/profile/') 
      else: 
       msg.append("disabled account") 
     else: 
      msg.append("invalid login") 

    return render_to_response('login.html') 

模板看起來如下...

{% block content %} 

     <form action="" method="post">{% csrf_token %} 
      Login:&nbsp; <input type="text" name="u"> 
      <br/> 
      Password:&nbsp; <input type="password" name="p"> 
      <input type="submit" value="Login"> 
     </form> 
    {% if errors %} 
     <ul> 
      {% for error in errors %} 
      <li>{{ error }}</li> 
      {% endfor %} 
     </ul> 
    {% endif %} 
    <a href="logout"> Logout </a> 

{% endblock %} 

回答

2

沒事琢磨出來的自己: 只需添加此JavaScript片段到您的模板頭:

<script type="text/javascript"> 
    $(document).bind("mobileinit", function(){ 
    ajaxEnabled:false;  
    }); 
    </script>