settings, apprename

This commit is contained in:
Pratyush Desai 2022-06-26 07:45:45 +05:30
parent 31a2e4004c
commit 4479bc8316
Signed by: pratyush
GPG Key ID: DBA5BB7505946FAD
5 changed files with 53 additions and 8 deletions

View File

@ -9,7 +9,7 @@ https://docs.djangoproject.com/en/4.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.0/ref/settings/
"""
import os
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
@ -52,10 +52,25 @@ MIDDLEWARE = [
ROOT_URLCONF = 'LibCasaAdministration.urls'
# TEMPLATES = [
# {
# 'BACKEND': 'django.template.backends.django.DjangoTemplates',
# 'DIRS': [],
# 'APP_DIRS': True,
# 'OPTIONS': {
# 'context_processors': [
# 'django.template.context_processors.debug',
# 'django.template.context_processors.request',
# 'django.contrib.auth.context_processors.auth',
# 'django.contrib.messages.context_processors.messages',
# ],
# },
# },
# ]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [os.path.join(BASE_DIR, "templates")],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
@ -67,7 +82,6 @@ TEMPLATES = [
},
},
]
WSGI_APPLICATION = 'LibCasaAdministration.wsgi.application'

View File

@ -15,8 +15,11 @@ Including another URLconf
"""
from django.contrib import admin
from django.urls import path, include
from django.conf.urls.static import static
from django.conf import settings
urlpatterns = [
path('api/', include('api.urls')),
path('admin/', admin.site.urls),
]
path('', include('forum.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

View File

@ -1,7 +1,7 @@
from django.contrib import admin
from .models import Post, Replie, Profile
from .models import Post, Reply, Profile
admin.site.register(Post)
admin.site.register(Replie)
admin.site.register(Reply)
admin.site.register(Profile)

7
forum/forms.py Normal file
View File

@ -0,0 +1,7 @@
from django import forms
from .models import Profile
class ProfileForm(forms.ModelForm):
class Meta:
model = Profile
fields = ('image', )

View File

@ -2,7 +2,8 @@ from django.shortcuts import render, redirect, HttpResponse, Http404
from .models import User, Profile, Post, Reply
from django.contrib.auth import authenticate, login, logout
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from .forms import ProfileForm
def UserRegister(request):
if request.method=="POST":
username = request.POST['username']
@ -34,6 +35,11 @@ def UserLogin(request):
return render(request, 'login.html', {'alert':alert})
return render(request, "login.html")
def UserLogout(request):
logout(request)
messages.success(request, "Successfully logged out")
return redirect('/login')
def forum(request):
profile = Profile.objects.all()
if request.method=="POST":
@ -59,4 +65,19 @@ def discussion(request, myid):
reply.save()
alert = True
return render(request, "discussion.html", {'alert':alert})
return render(request, "discussion.html", {'post':post, 'replies':replies})
return render(request, "discussion.html", {'post':post, 'replies':replies})
@login_required(login_url = '/login')
def myprofile(request):
if request.method=="POST":
user = request.user
profile = Profile(user=user)
profile.save()
form = ProfileForm(data=request.POST, files=request.FILES)
if form.is_valid():
form.save()
obj = form.instance
return render(request, "profile.html",{'obj':obj})
else:
form=ProfileForm()
return render(request, "profile.html", {'form':form})