Giving error Import at /post/new/ No module named 'blog.Forms'

Asked

Viewed 72 times

1

In this line: C: Users Fer Gomes djangogirls mysite blog views.py in , line 5 the code

from django.shortcuts import render
from django.utils import timezone
from .models import Post
from django.shortcuts import render, get_object_or_404
from .forms import PostForm
from django.shortcuts import redirect

# Create your views here.

def post_list(request):
    posts = Post.objects.filter(published_date__lte=timezone.now()).order_by('published_date')
    return render(request, 'blog/post_list.html', {'posts': posts})

def post_detail(request,pk):
    post = get_object_or_404(Post, pk=pk)
    return render(request, 'blog/post_detail.html', {'post': post})

def post_new(request):
    if request.method == "POST":
        form = PostForm(request.POST)
        if form.is_valid():
            post = form.save(commit=False)
            post.author = request.user
            post.published_date = timezone.now()
            post.save()
            return redirect('post_detail', pk=post.pk)
    else:
        form = PostForm()
    return render(request, 'blog/post_edit.html', {'form': form})
  • 1

    Fernanda, can you give more details in your question? For example the directory structure of your project?

  • Tengo el mismo error, y seguí al pie de la letra este tutorial: https://tutorial.djangogirls.org/es/django_forms/

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.