@login_required(login_url='/accounts/login/')
def upload(request):
    title = 'Upload New Post'
    current_profile = Profile.objects.filter(user_name=request.user.username).first()
    form = NewImageForm(request.POST, request.FILES)
    if ((request.method == 'POST') and request.FILES['new_image']):
        if form.is_valid():
            new_post = request.FILES['new_image']
            new_caption = form.cleaned_data['image_caption']
            new_upload = Image(image=new_post, image_name=generateNewName(), image_caption=new_caption, profile_id=current_profile, likes=0)
            new_upload.save()
            return redirect('Dashboard')
        else:
            form = NewImageForm()
    return render(request, 'upload.html', {'title': title, 'form': form, 'profile': current_profile})
@login_required(login_url='/accounts/login/')
def upload(request):
    title = 'Upload New Post'
    current_profile = Profile.objects.filter(user_name=request.user.username).first()
    form = NewImageForm(request.POST, request.FILES)
    if ((request.method == 'POST') and request.FILES['new_image']):
        if form.is_valid():
            new_post = request.FILES['new_image']
            new_caption = form.cleaned_data['image_caption']
            new_upload = Image(image=new_post, image_name=generateNewName(), image_caption=new_caption, profile_id=current_profile, likes=0)
            new_upload.save()
            return redirect('Dashboard')
        else:
            form = NewImageForm()
    return render(request, 'upload.html', {'title': title, 'form': form, 'profile': current_profile})