55 lines
1.2 KiB
Python
Executable File
55 lines
1.2 KiB
Python
Executable File
from django.shortcuts import render
|
|
from django.http import HttpResponse
|
|
from django.shortcuts import get_object_or_404, redirect
|
|
from django.contrib.auth.decorators import login_required
|
|
|
|
from .models import Photo
|
|
from .forms import PhotoForm
|
|
|
|
from django.conf import settings
|
|
|
|
def general_ctx(request):
|
|
ctx = {
|
|
'login_url': settings.LOGIN_URL,
|
|
'logout_url': '/accounts/logout/',
|
|
'user': request.user,
|
|
}
|
|
|
|
return ctx
|
|
|
|
def hello(request):
|
|
return HttpResponse('안녕하세요!')
|
|
|
|
def detail(request, pk, hidden=False):
|
|
photo = get_object_or_404(Photo, pk=pk)
|
|
|
|
msg = '<p>Photo No {}</p>\n'.format(pk)
|
|
msg += '<p>url : {url}</p>\n'.format(url=photo.image.url)
|
|
msg += '<p><img src="{url}">\n</p>'.format(url=photo.image.url)
|
|
msg += '<p>{}</p>\n'.format(photo.content)
|
|
|
|
if hidden is True:
|
|
msg += 'hidden 이지롱\n'
|
|
|
|
return HttpResponse(msg)
|
|
|
|
@login_required
|
|
def create(request):
|
|
if request.method == "GET":
|
|
form = PhotoForm()
|
|
elif request.method == "POST":
|
|
form = PhotoForm(request.POST, request.FILES)
|
|
|
|
if form.is_valid():
|
|
obj = form.save(commit=False)
|
|
obj.user = request.user
|
|
obj.save()
|
|
|
|
return redirect(obj)
|
|
|
|
ctx = general_ctx(request)
|
|
ctx['form'] = form
|
|
|
|
print(ctx['user'])
|
|
|
|
return render(request, 'edit.html', ctx) |