Now,I have designed a Demo . It contains username ,password, and language . But ,when I submit , it can't work . what's wrong ?
---------------------------------- 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}) ------------------------------------------------- login.py from login.models import Mlogin class login(object): def new(self,username,password): login_result = Mlogin.objects.create( username = username , password = password , ) return login_result def getresult(self): result = Mnewconrecord.objects.all() return result ------------------------------------ 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 -~----------~----~----~----~------~----~------~--~---