在做myblog项目时遇到的错误

来源:互联网 发布:got it 编辑:程序博客网 时间:2024/05/04 10:50

使用的工具:django + js
在使用模板将数据传递给js时 要记给字符串参数加引号

onclick=send_xx( {{ data | encrypt }})  #错误onclick=send_xx(" {{ data | encrypt }}")  #正确

在template 中调用url
在urls.py 定义的url 可以在temp中调用,调用前需要先命名

url(r’^test/’, Test.as_view(),name=’test’),
{{url base}}


*项目报错:**Reverse for ‘’ with arguments ‘()’ and keyword arguments ‘{}’ not found

There are 3 things I can think of off the top of my head:
我的错是第三种,虽然我也不知道为啥,改了个名字就可以了
1. Just used named urls, it’s more robust and maintainable anyway
2. Try using django.core.urlresolvers.reverse at the command line for a (possibly) better error

 from django.core.urlresolvers import reverse reverse('products.views.filter_by_led')

3. Check to see if you have more than one url that points to that view

PS: 后来发现原来我的extends 也修改了
原先 {% extends ‘base.html’ %} 改为 {% extends ‘./base.html’ %}后才能成功

PPPPS 忘记我的templates是改了路径,统一放在myblog/templates下的


js传数组给django:

$.ajax({
transitional:true,
data:{
data:list_
}
})

django:

request.POST.getlist(‘data’)


关于DIV无法触发onblur问题

默认情况下div 等元素是没有onblur事件的需要加上 tabindex=x 才行


关于js 计时器:
刚开始计时器只能执行一次,我就纳闷了,后来经查百度发现原来在使用计时器时需要调用自身。

        function send(){            s--;            alert(s)            t = setTimeout('send()',1000);            if(s==0){                s=60;                clearTimeout(t);            }

dropdown-menu 一经点击它就会消失,但是!!!

使用 event.stopPropagation();可以解决


在写正则的时候要注意,parttern字符串不一定要抱在 “/ /”中

re=new RegExp("[a-z]+\@[a-z]+\.[a-z]+");

修改用户密码:
要注意不能使用 request.user.set_password( newpass)
要使用 :

from django.contrib.auth.hasher import make_passworduser.password = make_password(newpass)

因为前者只有在密码为空时才会设置