我是DJango的新手,我对表格有些怀疑。这是代码,感谢您的帮助:D
这是我看来的错误: http://www.passportjs.org/docs/logout/
目录和文件:
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
templates / 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 %}
urls.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'),
]
views.py代码:
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})
答案 0 :(得分:1)
看起来您的forms.py
位于templates/blog
目录中。它应位于blog
旁边的主models.py
目录中。