我正在通过视频教程学习django。我注册了注册部分。当我在registration_form.html中写了一堆代码时,它没有显示在浏览器上。默认页面包含用户名,电子邮件,密码,当我去网址127.0.0.1:8000/accounts/register时,密码(再次)出现。我正在尝试加载脆弱的表单。但它甚至没有出现在浏览器和一段问题上也没有当我尝试加载网址时。 我的registration_form.html是
{% extends "registration/registration_base.html" %}
{% load i18n %}
{% load crispy_forms_tags %}
{% block title %}{% trans "Register for an account" %}{% endblock %}
{% block content %}
<div class='col-sm-6 col-sm-offset-3'>
<form method="post" action="">
{% csrf_token %}
{{ form|crispy }}
<input class='btn btn-primary'type="submit" value="{% trans 'Submit' %}" />
</form>
</div>
{% endblock %}
{% comment %}
**registration/registration_form.html**
Used to show the form users will fill out to register. By default, has
the following context:
``form``
The registration form. This will be an instance of some subclass
of ``django.forms.Form``; consult `Django's forms documentation
<http://docs.djangoproject.com/en/dev/topics/forms/>`_ for
information on how to display this in a template.
{% endcomment %}
我的registration_base.html是
{% extends "base.html" %}
和settings.py是
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/dev/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
EMAIL_HOST='smtp.gmail.com'
EMAIL_PORT=587
EMAIL_USE_TLS=True
# Application definition
INSTALLED_APPS = [
#django_ap[s
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
#third_party_apps
'crispy_forms',
'registration',
#my_apps
'newsletter',
]
MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'trydjango18.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},]
WSGI_APPLICATION = 'trydjango18.wsgi.application'
# Database
# https://docs.djangoproject.com/en/dev/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/dev/ref/settings/#auth-password- validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},]
# Internationalization
# https://docs.djangoproject.com/en/dev/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/dev/howto/static-files/
STATIC_URL = '/static/' STATIC_ROOT=os.path.join(os.path.dirname(BASE_DIR),"static_in_env","static_root")
STATICFILES_DIRS=(
os.path.join(BASE_DIR,"static_in_pro","our_static"),
#os.path.join(BASE_DIR,"static_in_pc"),
#'/var/www/static',
)
MEDIA_URL='/media/' MEDIA_ROOT=os.path.join(os.path.dirname(BASE_DIR),"static_in_env","media_root")
#crispy forms
CRISPY_TEMPLATE_PACK='bootstrap3'
#Django registration redux
ACCOUNT_ACTIVATION_DAYS=7
REGISTRATION_AUTO_LOGIN=True
SITE_ID=1
和mu urls.py是
from django.conf import settings
from django.conf.urls import include,url
from django.conf.urls.static import static
from django.contrib import admin
urlpatterns = [
url(r'^$','newsletter.views.home',name='home'),
url(r'^contact/$','newsletter.views.contact',name='contact'),
url(r'^about/$','trydjango18.views.about',name='about'),
url(r'^admin/', include(admin.site.urls)),
url(r'^accounts/', include('registration.backends.default.urls')),]
我的views.py是
from django.conf import settings
from django.core.mail import send_mail
from django.shortcuts import render
from .forms import SignUpForm,ContactForm
# Create your views here.
def home(request):
title='welcome'
form=SignUpForm(request.POST or None)
context={
"title":title,
"form":form
}
if form.is_valid():
instance=form.save(commit=False)
full_name=form.cleaned_data.get("full_name")
if not full_name:
full_name="shocker"
instance.full_name=full_name
# print instance.email
# print instance.timestamp
instance.save()
context={"title":"Thank you"}
return render(request,"home.html",context)
def contact(request):
title='Contact Us'
title_align_center=False
form=ContactForm(request.POST or None)
context={
"form":form,
"title":title,
"title_align_center":title_align_center,
}
return render(request,"forms.html",context)
我不知道我哪里出错了。请帮帮我......