Python 邮局的进口恐怖/新的al-crear联合国规范(formulario con Django)
我是DJango的新手,对表单有一些疑问。这是代码,我将感谢你的帮助:D 这就是我看到的错误: 目录和文件:Python 邮局的进口恐怖/新的al-crear联合国规范(formulario con Django),python,django,django-forms,Python,Django,Django Forms,我是DJango的新手,对表单有一些疑问。这是代码,我将感谢你的帮助:D 这就是我看到的错误: 目录和文件: blog |--_pycachce_ |--migrations |--static |--templates |--blog |--base.html |--forms.py |--post_bio.html |--post_detail.html |--post_edit.
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_edit.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 %}
看起来您的
forms.py
位于templates/blog
目录中。它应该在主blog
目录中,与models.py
一起,看起来好像forms.py
在templates/blog
目录中。它应该在主博客
目录中,与models.py
一起
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'),
]
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
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})