urls.py
from django.conf.urls import include, url
from . import views
from blog.views import *
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls), # Esto no lo borres porque sino no vas a poder acceder al /admin
url(r'^$', post_list, name='post_list'), # Si va al raiz www.tusitio.com que lo atienda el index
url(r'^formulario/$', formulario, name='formulario'), # Si ingresa en www.tusitio.com/contactos entonces sera atendido por la vista de contactos
url(r'^tabla/$', tabla, name='tabla'), # Si ingresa en www.tusitio.com/contactos entonces sera atendido por la vista de contactos
url(r'^gracias/' , 'blog.views.gracias' , name='gracias')
]
formulario.html
{% load staticfiles %}
<html>
<head>
<title>Sergito</title>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<link href='//fonts.googleapis.com/css?family=Lobster&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="{% static 'css/blog.css' %}">
</head>
<body>
<div class="page-header" align="center">
<h1>Esto es una prueba</h1>
<a href="post_list">Inicio</a>
<a href="formulario">Formulario</a>
<a href="tabla">Tabla</a>
</div>
<div class="content" align="center">
<form action="/blog/templates/blog/" method="post">{% csrf_token %}
{{ form.as_table }}
<input type="submit" value="Enviar">
</form>
</div>
</body>
</html>
views.py
from django.shortcuts import render
from django.template import loader, Context
from django.core import serializers
from django.views.generic import TemplateView
from django.shortcuts import redirect
from django.http import HttpResponseRedirect
from .forms import formulario
def formulario(request):
if request.method == 'POST':
form = formulario(request.POST)
if form.is_valid():
return HttpResponseRedirect('/blog/templates/blog/gracias/')
else:
form = formulario()
return render(request,'formulario.html',{
'form': form,
})
forms.py
from django import forms
class formulario(forms.Form):
nombre = forms.CharField(max_length=100)
mensaje = forms.CharField()
mail = forms.EmailField()