mardi 25 août 2020

The view blogapp.views.blogpost didn't return an HttpResponse object. It returned None instead

from django import forms 
from .models import Blog

I just rewrite code this point, from ↓:

# class BlogPost(forms.ModelForm):
#     class Meta:
#         model = Blog
#         fields = ['title', 'body']

to ↓:

class BlogPost(forms.Form):
    email = forms.EmailField()
    files = forms.FileField()
    url = forms.URLField()
    words = forms.CharField(max_length=200)
    max_number = forms.ChoiceField(choices=[('1','one'), ('2','two'),('3','three')])

and views.py file is here ↓:

from django.shortcuts import render, get_object_or_404, redirect
    from .models import Blog
    from django.utils import timezone
    from .form import BlogPost
    from django.views.decorators.http import require_http_methods
    # Create your views here.
def home(request):
    blogs = Blog.objects #쿼리셋
    return render(request, 'home.html', {'blogs'`enter code here`:blogs})

def detail(request, blog_id):
    details = get_object_or_404(Blog, pk=blog_id)
    return render(request, 'detail.html', {'details':details})

def new(request):
    return render(request, 'new.html')


def create(request):
    blog = Blog()
    blog.title = request.GET['title']
    blog.body = request.GET['body']
    blog.pub_date = timezone.datetime.now()
    blog.save()
    return redirect('/blog/'+str(blog.id)) #이 URL로 넘기세요 처리된 정보를 

def blogpost(request):
    if request.method =='POST':
        form = BlogPost(request.POST)
        if form.is_valid():
            post = form.save(commit=False)
            # post.pub_date = timezone.now()
            post.save()
            return redirect('home')

    else:
        form = BlogPost()
        return render(request, 'newblog.html',{'form':form})

I don't know why I only rewrite 'form.py' file, but vscode program says "The view blogapp.views.blogpost didn't return an HttpResponse object. It returned None instead."

what should I do?? help..




Aucun commentaire:

Enregistrer un commentaire