View
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", {})
project url
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('pages.urls')),
]
App url
urlpatterns = [
path('', HomePageView, name = 'home'),
path('namev/', Namev_view),
#path('', HomePageView),
#path('namev/', Nameview_view),
]
Note, I have not written any code at home.html template and it is rendering well
Chief Programmer,
ICT Unit, UNN
--Please share code for home.html & urls.py. Also have you included the app name in the settings.py?
Thanks,
Bruckner de Villiers
083 625 1086
From: <django-users@googlegroups.com> on behalf of Ifeanyi Chielo <ifeanyi.chielo@unn.edu.ng>
Reply to: <django-users@googlegroups.com>
Date: Saturday, 04 April 2020 at 02:51
To: Django users <django-users@googlegroups.com>
Subject: Re: Working with forms
Thanks Victor,
I did it and it does not make any cnange
On Saturday, April 4, 2020 at 1:41:19 AM UTC+1, victor awakan wrote:In the form template tag, shouldn't it be {{ form.as_p}} tag?
On Sat 4. Apr 2020 at 3.35, Ifeanyi Chielo <ifeany...@unn.edu.ng> wrote:
Hello,I developed a form with a single field, but this form displays only the submit button at the browser as shown in the image below. Please how can I correct this and also save the field to the MySQL table. My code is also shown below
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...@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.--
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/9825aec7-7e87-4d4a-80f9-634cb9e4dd59%40googlegroups.com.
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/E47A5C26-9855-4ED7-86AD-3F427A2E88B7%40gmail.com.
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/CAOcS8H3QEdWtT%3DRn4P%2B9LFA%3DjTPQHgCi3V_BYwbOsc6DHcD%2BRQ%40mail.gmail.com.
No comments:
Post a Comment