Commit 1eb2ed28 authored by Anya Habana's avatar Anya Habana

Displayed and rendered form in homepage

parent 917ae4bb
from django.shortcuts import render from django.shortcuts import render, redirect
from django.http import HttpResponse from django.http import HttpResponse
from django.template import loader from django.template import loader
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
from .models import WidgetUser from .models import WidgetUser
from .forms import WidgetUserForm
def index(request): def index(request):
user_list = WidgetUser.objects.order_by("last_name") user_list = WidgetUser.objects.order_by("last_name")
...@@ -12,6 +13,16 @@ def index(request): ...@@ -12,6 +13,16 @@ def index(request):
template = loader.get_template("users/index.html") template = loader.get_template("users/index.html")
return HttpResponse(template.render(context, request)) return HttpResponse(template.render(context, request))
def newuser(request):
if request.method == "POST":
user_form = WidgetUserForm(request.POST)
if user_form.is_valid():
new_user = user_form.save()
return redirect("homepage:index", pk=new_user.pk)
else:
user_form = WidgetUserForm()
return render(request, 'newuser.html', {"user_form": user_form})
class WidgetUserDetailView(DetailView): class WidgetUserDetailView(DetailView):
model = WidgetUser model = WidgetUser
template_name = "users/users.html" template_name = "users/users.html"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment