I'm using Django 1.11.4,
root app
url(r'^contacto/', include('contacto.urls'), name='contacto'),
contact_app / urls.py
from django.conf.urls import url, include
from contacto.views import contacto
urlpatterns = [
url(r'^$', contacto, name='contacto'),
]
contact_app / forms.py
from django import forms
class formulario(forms.Form):
nombre = forms.CharField(max_length=25)
email = forms.EmailField(max_length=25)
telefono = forms.CharField(max_length=15)
mensaje = forms.CharField(max_length=300)
contact_app / views.py
from __future__ import unicode_literals
from django.shortcuts import render
from django.http import HttpResponse
from.models import Contacto
def contacto(request):
contactos = Contacto.objects.all()
return render(request, 'contacto.html', {'contactos': contactos})
contact_app / models.py
from django.db import models
class Contacto(models.Model):
nombre = models.CharField(max_length=25)
email = models.CharField(max_length=25)
telefono = models.CharField(max_length=15)
mensaje = models.CharField(max_length=300)
template / contacto.html
<body>
<form action="/contacto/" method="post">{% csrf_token %}
{{ form.as_table }}
<input type="submit" value="Enviar">
</form>
When doing runserver I get this:
Terminal
[07 / May / 2018 23:35:42] "POST / contact / HTTP / 1.1" 200 472
I can not find the solution, I just want you to upload the form in the html, and that information can be seen in admin. Thanks in advance for the help