sorry , the correct code is below . I change the login.py into
forms.py
> ----------------------------------
> settings.py
>
> # Django settings for Test project.
>
> DEBUG = True
> TEMPLATE_DEBUG = DEBUG
>
> ADMINS = (
>     # ('Your Name', 'your_em...@domain.com'),
> )
>
> MANAGERS = ADMINS
>
> DATABASE_ENGINE = 'mysql'           # 'postgresql_psycopg2',
> 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
> DATABASE_NAME = 'test'             # Or path to database file if using
> sqlite3.
> DATABASE_USER = 'root'             # Not used with sqlite3.
> DATABASE_PASSWORD = '123456'         # Not used with sqlite3.
> DATABASE_HOST = '127.0.0.1'             # Set to empty string for
> localhost. Not used with sqlite3.
> DATABASE_PORT = ''             # Set to empty string for default. Not
> used with sqlite3.
> TIME_ZONE = 'America/Chicago'
> LANGUAGE_CODE = 'en'
> SITE_ID = 1
> USE_I18N = True
> MEDIA_ROOT = ''
> MEDIA_URL = ''
> ADMIN_MEDIA_PREFIX = '/media/'
>
> SECRET_KEY = '%5(1wm^_wws6f3pq#_ypz...@#htypxft+7i*lcp4jx0nf5192'
>
> TEMPLATE_LOADERS = (
> )
>
> MIDDLEWARE_CLASSES = (
>     'django.contrib.sessions.middleware.SessionMiddleware',
>     'django.middleware.locale.LocaleMiddleware',
>     'django.middleware.common.CommonMiddleware',
>     'django.contrib.auth.middleware.AuthenticationMiddleware',
>     'django.middleware.doc.XViewMiddleware',
> )
>
> ROOT_URLCONF = 'Test.urls'
>
> TEMPLATE_DIRS = (
>                  'D:/work/Test/templates'
> )
>
> TEMPLATE_CONTEXT_PROCESSORS = (
>     'django.core.context_processors.i18n',
>     'django.core.context_processors.request',
> )
>
> INSTALLED_APPS = (
>     'django.contrib.auth',
>     'django.contrib.contenttypes',
>     'django.contrib.sessions',
>     'django.contrib.sites',
>     'Test.login',
> )
> -------------------------------------
>
> urls.py
>
> from django.conf.urls.defaults import *
> from Test.login.views import login_method
>
> urlpatterns = patterns('',
>         (r'^i18n/', include('django.conf.urls.i18n')),
>         (r'^test/$',login_method),
> )
> ----------------------------------
> views.py
>
> from django.shortcuts import render_to_response
> from Test.login.forms import LoginForm
> from django.utils.translation import check_for_language,get_language
> def login_method(request):
>     r_list = ''
>     username = ''
>     password = ''
>     lang = request.LANGUAGE_CODE
>     print 'before POST,the language is %(lang)s' %{'lang':lang}
>     if request.method == 'POST':
>         lang_code=request.POST.get("language")
>         request.session['django_language'] = lang_code
>         session = request.session.get('django_language')
>         form = LoginForm(request.POST)
>         if form.is_valid():
>            username = form.cleaned_data['username']
>            password = form.cleaned_data['password']
>            form = LoginForm()
>     else:
>         form = LoginForm()
>     r_list = {'username':username,'password':password}
>     return render_to_response('test.html',
> {'form':form,'r_list':r_list})
> -------------------------------------------------
>forms.py

from django import forms
from django.forms import widgets
from django.utils.translation import gettext_lazy as _

class LoginForm(forms.Form):
    array = (
    ('zh-CN', _('Simplified chinese')),
    ('zh-TW', _('Traditional chinese')),
    ('en-us', _('English')),
    )

    username = forms.CharField(max_length=50,required=True,label = _
("username"))
    password = forms.CharField
(max_length=50,required=True,widget=widgets.PasswordInput(),label = _
("password"))
    language = forms.CharField
(max_length=50,required=True,widget=forms.Select(choices=array),label
= _("language"))
> ------------------------------------
> test.html
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
> {% load i18n %}
> {% get_current_language as LANGUAGE_CODE %}
> <html xmlns="http://www.w3.org/1999/xhtml";>
> <head>
> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
> <title>test</title>
> </head>
>
> <body align="center">
> <br/>
> <br/>
> <center>{% trans "login" %}</center>
> <hr width="800">
> <br/>
> <center>
> <form action="." method="post">
> <table>
> {{form}}
> </table>
> <br/>
> <input type="submit" value={% trans "Sumbmit" %}><br/><br/>
> </form>
> </center>
> <br />
> <br />
> <hr width="800"/>
> <center>
> {% ifnotequal r_list.get('username') ''%}
> {% trans 'username' %} : {{r_list.username|default:"nothing"}} {%
> trans 'password' %} : {{r_list.password|default:"nothing"}}<br />
> {% endifnotequal %}
> </center>
> --------------------------------------------------
>
> Is there anything wrong ?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to