Commit 445200ca authored by Julia Santos's avatar Julia Santos

Implemented logging in function, redirects to homepage

parent 6446f90c
from django import forms
class LoginForm(forms.Form):
user = forms.CharField(label = 'username', max_length = 100)
password = forms.CharField(widget = forms.PasswordInput())
\ No newline at end of file
<html>
<title> Home </title>
<body>
<main>
HELLO
</main>
</body>
</html>
\ No newline at end of file
<html>
<body>
You are : <strong>{{username}}</strong>
</body>
</html>
\ No newline at end of file
<h2>Log In</h2>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Log In</button>
</form>
\ No newline at end of file
from django.conf.urls import url
from django.conf import settings
from django.conf.urls.static import static
from django.views.generic import TemplateView
from django.urls import include
from .views import UserListView, ProductListView
urlpatterns = [
url(r'^fridge/list/', ProductListView.as_view(), name='fridgeL'),
url('accounts/', include('django.contrib.auth.urls')),
url('', TemplateView.as_view(template_name='homepage.html'), name='home')
]
if settings.DEBUG:
......
from django.views.generic import ListView
from .models import User, Product_Type, Item, Recipe
from django.db.models import Q
from .forms import LoginForm
from django.http import HttpResponseRedirect
from django.shortcuts import render
class UserListView(ListView):
model = User
......@@ -15,4 +18,19 @@ class ProductListView(ListView):
context_object_name = 'product'
def get_queryset(self):
return Product_Type.objects.all().order_by('Product_Name')
\ No newline at end of file
return Product_Type.objects.all().order_by('Product_Name')
def login(request):
username = "not logged in"
if request.method =="POST":
MyLoginForm = LoginForm(request.POST)
if MyLoginForm.is_valid():
username = MyLoginForm.cleaned_data['username']
#return HttpResponseRedirect('/fridge/list')
else:
MyLoginForm = Loginform()
return render(request, loggedin.html,{"username" : username})
......@@ -55,7 +55,7 @@ ROOT_URLCONF = 'HungerBuster.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [str(os.path.join(BASE_DIR,'templates'))],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
......@@ -123,7 +123,11 @@ USE_TZ = True
# https://docs.djangoproject.com/en/1.11/howto/static-files/
STATIC_URL = '/static/'
#for displaying images
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'), )
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
\ No newline at end of file
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
#for login
LOGIN_REDIRECT_uRL = '/'
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