Sunday 15 April 2012

html - Django "if request.method == 'POST':" fails -



html - Django "if request.method == 'POST':" fails -

hi have unusual problem in new django project.

i'm testing nameform illustration django documentation working froms. seems easy 1 somehow when seek submit name nil happens not page reload.

form.py

from django import forms class nameform(forms.form): your_name = forms.charfield(label='your name', max_length=100)

views.py

from django.shortcuts import render django.http import httpresponseredirect groupbuilder import forms def groupbuilder(request): if request.method == 'post': form = forms.nameform(request.post) if form.is_valid(): homecoming httpresponseredirect('/thanks/') else: form = forms.nameform() homecoming render(request, 'groupbuilder.html', {'form': form})

the template:

<form action="/your-name/" method="post"> {% csrf_token %} { form.as_p }} <input type="submit" value="submit" /> </form>

setting.py

""" django settings crosslfg project. more info on file, see https://docs.djangoproject.com/en/1.6/topics/settings/ total list of settings , values, see https://docs.djangoproject.com/en/1.6/ref/settings/ """ # build paths within project this: os.path.join(base_dir, ...) import os django.utils.translation import ugettext_lazy _ template_context_processors = ( "django.contrib.auth.context_processors.auth", "django.core.context_processors.debug", "django.core.context_processors.i18n", "django.core.context_processors.media", "django.core.context_processors.static", "django.core.context_processors.tz", "django.contrib.messages.context_processors.messages", #"frontpage.context_processors.contactform", ) debug = true template_debug = debug admins = ( # ('your name', 'your_email@example.com'), ) managers = admins base_dir = os.path.dirname(os.path.dirname(__file__)) project_path = '/home/kbrothers/crosslfg/' template_path = os.path.join(project_path, 'templates') static_path = os.path.join(project_path,'static') static_url = '/static/' database_path = os.path.join(project_path,'users.db') #locale_paths = os.path.join(project_path, 'locale',) locale_paths = ('/home/kbrothers/crosslfg/locale',) # quick-start development settings - unsuitable production # see https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/ # security warning: maintain secret key used in production secret! secret_key = **** # security warning: don't run debug turned on in production! debug = true crispy_template_pack = 'bootstrap3' allowed_hosts = [] # application definition installed_apps = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'accounts', 'main_app', 'groupbuilder', 'crispy_forms', ) template_loaders = ( 'django.template.loaders.filesystem.loader', 'django.template.loaders.app_directories.loader', # 'django.template.loaders.eggs.loader', ) template_dirs = ( os.path.join(project_path, 'templates'), os.path.join(project_path, 'main_app/templates'), os.path.join(project_path, 'accounts/templates'), os.path.join(project_path, 'groupbuilder/templates'), ) middleware_classes = ( 'django.contrib.sessions.middleware.sessionmiddleware', 'django.middleware.locale.localemiddleware', 'django.middleware.common.commonmiddleware', 'django.middleware.csrf.csrfviewmiddleware', 'django.contrib.auth.middleware.authenticationmiddleware', 'django.contrib.messages.middleware.messagemiddleware', 'django.middleware.clickjacking.xframeoptionsmiddleware', # uncomment next line simple clickjacking protection: 'django.middleware.clickjacking.xframeoptionsmiddleware', ) root_urlconf = 'crosslfg.urls' wsgi_application = 'crosslfg.wsgi.application' # database # https://docs.djangoproject.com/en/1.6/ref/settings/#databases mail_use_tls = true email_host = '****' email_port = **** email_host_user = '********' email_host_password = '********' #crispy_template_pack = 'bootstrap3' databases = { 'default': { 'engine': 'django.db.backends.sqlite3', # add together 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. 'name': database_path, # or path database file if using sqlite3. # next settings not used sqlite3: 'user': '', 'password': '', 'host': '', # empty localhost through domain sockets or '127.0.0.1' localhost through tcp. 'port': '', # set empty string default. } } # internationalization # https://docs.djangoproject.com/en/1.6/topics/i18n/ language_code = 'en' #language_code = 'de' #language_code = 'fr' language_cookie_name = 'wm_lang' time_zone = 'utc' languages = ( ('en', _('english')), #('de', _('german')), #('fr', _('french')), ) use_i18n = true use_l10n = true use_tz = true # static files (css, javascript, images) # https://docs.djangoproject.com/en/1.6/howto/static-files/

the unusual thing if set

return httpresponseredirect('/thanks/')

right after "else" in

if request.method == 'post':

statement, can't fill out form when seek visit form url. takes straight /thanks/. request.method check fails.

what miss??

problem solved:

<script src="{{static_url}}js/plugins/jqbootstrapvalidation.js"></script>

from jqbootstrapvalidation caused problem. i'm not sure why there must have been interference form functionalities.

anyway help

html django post

No comments:

Post a Comment