Friday, December 26, 2008

Should I make a new wheel?

I must admit that I'm a pythonic,I like everything of python.After a long time to experiment Django. I think I need my own web framework.To tell you the turth,I'm a java fan previously.I like Hibernate,spring,struts etc.So I decided to make a simple but better web framework, its ORM like hibernate, its web architecture like spring, and may be I'll create a simple server, I refer to the Django,CherryPy ,both of them are enough good.may be I just need reuse them. who knows,but for now my plan is write a simple web server firstly. I think cherryPy's server is a good reference.

Tuesday, December 16, 2008

clean_data and cleaned_data

When we use the form object in Django,Frequently,we need validate the fields of the form.for example:
>>>python manage.py shell
>>>from pageage1 import MyForm
>>>form=MyForm({'username':'Eric','email':'test@test.com'})
>>>form.is_valid()
True

We could access the form's data by attribute form.data, If it's validated we can also access the valid data by attribute form.clean_data,but when you upgrade to Django 1.0,this attribute will be no long in use.Instead of it,you should use the attribute cleaned_data:
...
>>>form.clean_data # Django 0.96
>>>form.cleaned_data # Django 1.0

Monday, December 15, 2008

errors and has_errors

There is a slight difference between Django 1.0 and 0.95.When we use user authentication in Django,and we create pass a form object to login.html template for example.
<div style="margin-left: 40px;"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Django Bookmarks - User Login</title>
</head>
<body>
<h1>User Login</h1>
{%if form.has_errors%}
<p>Your username and password didn't match.
Please try again.</p>
{%endif%}
<form method="post" action=".">
<p><label for="id_username">Username:</label>
{{ form.username }}</p>
<p><label for="id_password">Password:</label>
{{ form.password }}</p>
<input type="hidden" name="next" value="/">
<input type="submit" value="login">
</form>
</body>
</html>

In version 0.95,it's work fine.but if you run it under the version 1.0,you can't see the error message when you login-failing.The question is in Django 1.0,the attribute of form object is errors instead of has_error.so change the attribute it'll work well.