ImportError at post / new when creating a form with Django

0

I'm starting at DJango and I have some doubts about the forms, here's the code, I'd appreciate your help: D

This is the error that appears:

Directories and files:

  blog
   |--_pycachce_
       |--migrations
       |--static
       |--templates
           |--blog
           |--base.html
           |--forms.py
           |--post_bio.html
           |--post_detail.html
           |--post_edit.html
           |--post_list.html
       |--models.py
       |--tests.py
       |--urls.py
       |--views.py
       |--_init_.py
       |--admin-py

Post_detail Code.html:

    {% extends 'blog/base.html' %}
      {% block content %}
        <h1>New post</h1>
        <form method="POST" class="post-form">{% csrf_token %}
            {{ form.as_p }}
            <button type="submit" class="save btn btn-default">Save</button>
        </form>
    {% endblock %}

Urls.py code:

from django.conf.urls import url
from . import views

urlpatterns = [
    url(r'^$', views.post_list),
    url(r'^post/(?P<pk>[0-9]+)/$', views.post_detail, name='post_detail'),
    url(r'^post/new/$', views.post_new, name='post_new'),
]

views.py code:

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

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):
    form = PostForm()
    return render(request, 'blog/post_edit.html', {'form': form})
    
asked by Grace Nikole 15.01.2018 в 18:23
source

1 answer

2

the forms.py has to be in the same folder where the others are .py, now you have it inside the template folder

    
answered by 15.01.2018 / 22:13
source