Commit 19e5e4e9 authored by James Esguerra's avatar James Esguerra

Added KeyForm to "add_key" view

parent 0caea6b5
...@@ -6,6 +6,7 @@ urlpatterns = [ ...@@ -6,6 +6,7 @@ urlpatterns = [
path('home/', views.ShowHome, name='home'), path('home/', views.ShowHome, name='home'),
path('profile/', views.ShowProfile, name='profile'), path('profile/', views.ShowProfile, name='profile'),
path('key/', views.ShowKey, name='key'), path('key/', views.ShowKey, name='key'),
path('add_key/', views.ShowAddKey, name='add_key'),
path('this_week/', views.ShowThisWeek, name='this_week'), path('this_week/', views.ShowThisWeek, name='this_week'),
path('today/', views.ShowToday, name='today'), path('today/', views.ShowToday, name='today'),
] ]
import datetime import datetime
from django.shortcuts import render from django.shortcuts import render, redirect
from django.http import HttpResponse from django.http import HttpResponse
from .forms import HomeForm from .forms import HomeForm, KeyForm
def ShowHome(request): def ShowHome(request):
...@@ -25,6 +25,18 @@ def ShowKey(request): ...@@ -25,6 +25,18 @@ def ShowKey(request):
return render(request, 'key.html') return render(request, 'key.html')
def ShowAddKey(request):
form = KeyForm()
if request.method == 'POST':
form = KeyForm(request.POST)
if form.is_valid():
form.save()
return redirect('key')
return render(request, 'add_key.html', {'form': form})
def ShowThisWeek(request): def ShowThisWeek(request):
return render(request, 'this_week.html') return render(request, 'this_week.html')
......
{% extends 'base.html' %}
{% load static %}
{% block title %} Key {% endblock %}
{% block header %} Key {% endblock %}
{% block content %}
<form action='' method='POST'>
{% csrf_token %}
{{ form }}
<input type='submit' name='Submit' value='Add'>
</form>
{% endblock %}
...@@ -7,6 +7,6 @@ ...@@ -7,6 +7,6 @@
{% block content %} {% block content %}
<a href='{% url 'home' %}'><button type='button'> Add Key </button></a> <a href='{% url 'add_key' %}'><button type='button'> Add Key </button></a>
{% endblock %} {% endblock %}
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