View.py
from django.http import HttpResponseRedirect
from django.shortcuts import render
from .models import Namerec
from .forms import NameForm
from django.views.generic import TemplateView
def HomePageView (request, *args, **kwargs):
return render(request,"home.html", {})
def Namev_view (request):
if request.method == 'POST':
form = NameForm (request.POST)
if NameForm.is_valid():
NameForm.save()
context = {
'form': form
}
return render(request, 'namev.html', {})
form.py
from .models import Namerec
from django import forms
class NameForm(forms.Form):
your_name = forms.CharField(label='Your name', max_length=100)
template (namev.htlm)
<form action="/namev/" method="Post">
{% csrf_token %}
{{ form }}
<input type="submit" value="Submit">
</form>
Model.py
from django.db import models
class Namerec(models.Model):
your_name = models.CharField(max_length=30)
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f50577dd-d5c0-4478-8993-7bab533f24f9%40googlegroups.com.

No comments:
Post a Comment