Python中文
首页
教程
问答
标签
搜索
登录
注册
Django show render_to_response in临时
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>你好,提前谢谢你。</p> <p>我知道这是一个完全没有问题的问题,我已经在各个论坛搜索,阅读和重读了文件,所以请温柔。</p> <p>我有一个观点:</p> <pre><code>#views.py from django.shortcuts import render_to_response from django.shortcuts import render from django.http import HttpResponse, HttpRequest, HttpResponseRedirect from acme.acmetest.models import Player from acme.acmetest.models import PickForm def playerAdd(request, id=None): form = PickForm(request.POST or None, instance=id and Player.objects.get(id=id)) # Save new/edited pick if request.method == 'POST' and form.is_valid(): form.save() return HttpResponseRedirect('/draft/') #return render_to_response('makepick.html', {'form':form}) return render(request, 'makepick.html', {'form':form}) def draftShow(request): draft_list = ['1', 'hello', 'test', 'foo', 'bar'] #draft_list = Player.objects.all() #return render_to_response('makepick.html', {'draft_list' :draft_list}, context_instance=RequestContext(request)) return render_to_response('makepick.html', {'draft_list' :draft_list}) </code></pre> <p>我正在尝试将其呈现到template.html页面:</p> <pre><code>#makepick.html <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <HTML lang="en"> <head> <title>Pick</title> </head> <body> <form method="POST" action=""> {% csrf_token %} <table>{{ form }}</table> <input type="submit" value="Draft Player" </form><br /><br /> Your picks so far:<br /> {% for draft in draft_list %} {{ draft.playernumber }} {% endfor %} </body> </HTML> </code></pre> <p>其中playernumber是models.py中模型类“Player”中的字段。</p> <pre><code>#urls.py from django.conf.urls.defaults import patterns, include, url from acme.acmetest import views urlpatterns = patterns('', ('^$', 'acme.acmetest.views.playerAdd'), ) </code></pre> <p>谢谢你的帮助!</p> <p>dp公司</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>确保<code>makepick.hmtl</code>位于应用程序的<code>templates</code>目录或模板目录中。</p> <p>您可以签入视图以验证<code>Player.objects.all()</code>是否实际返回了某些内容。确保playernumber是Player对象的实际属性。</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
无法使用Django/mongoengine连接到MongoDB(身份验证失败)
1 回答
无法使用Django\u mssql\u后端迁移到外部hos
8 回答
无法使用Django&Python3.4连接到MySql
5 回答
无法使用Django+nginx上载媒体文件
3 回答
无法使用Django1.6导入名称模式
4 回答
无法使用Django1.7和mongodb登录管理站点
10 回答
无法使用Djangoadmin创建项目,进程使用了错误的路径,因为我事先安装了错误的Python
3 回答
无法使用Djangockedi验证CBV中的字段
10 回答
无法使用Djangocketditor上载图像(错误400)
5 回答
无法使用Djangocron进行函数调用
7 回答
无法使用Djangofiler djang上载文件
6 回答
无法使用Djangokronos
4 回答
无法使用Djangomssql provid
10 回答
无法使用Djangomssql连接到带有Django 1.11的MS SQL Server 2016
8 回答
无法使用Djangomssq迁移Django数据库
2 回答
无法使用Djangonox创建用户
6 回答
无法使用Djangopyodb从Django查询SQL Server
2 回答
无法使用Djangopython3ldap连接到ldap
1 回答
无法使用Djangoredis连接到redis
6 回答
无法使用Django中的FK创建新表
10 回答