Python Django:将pk从表单提交的数据拉入后续URL
因此,我有一个页面,其中包含一个表单,用户可以向数据库提交数据,第二个页面包含通过使用指定的pk值从该记录中获取的特定字段 我的问题是,我是否可以使用submit按钮将数据发布到数据库,然后立即加载URL,其中包含提交记录中的pk值,以使用某些字段?或者这需要分两步完成吗?i、 e.1。将数据插入数据库,然后插入2。加载带有相关pk的URLPython Django:将pk从表单提交的数据拉入后续URL,python,django,django-forms,django-views,django-urls,Python,Django,Django Forms,Django Views,Django Urls,因此,我有一个页面,其中包含一个表单,用户可以向数据库提交数据,第二个页面包含通过使用指定的pk值从该记录中获取的特定字段 我的问题是,我是否可以使用submit按钮将数据发布到数据库,然后立即加载URL,其中包含提交记录中的pk值,以使用某些字段?或者这需要分两步完成吗?i、 e.1。将数据插入数据库,然后插入2。加载带有相关pk的URL url.py: from django.urls import path from django.conf.urls import url, include
url.py
:
from django.urls import path
from django.conf.urls import url, include
from django.views.generic import TemplateView
from .views import *
from . import views
urlpatterns = [
url(r'^$', UserView.as_view(), name='user_new.html'),
# form temporarily directs here after saving the data to the DB
url(r'^thanks/$', TemplateView.as_view(template_name='thanks.html'), name='thanks'),
# I would like it to go here instead
path('adherence_agreement/<int:id>', views.adherence_agreement, name='adherence_agreement'),
]
from django.views.generic.edit import FormView,CreateView
class UserView(CreateView):
template_name = 'user_new.html'
form_class = UserForm
success_url = 'thanks/'
def post(self, request, *args, **kwargs):
self.object = None
if request.method == 'POST':
form = UserForm(data=request.POST)
if form.is_valid():
form.save()
return self.form_valid(form)
else:
return self.form_invalid(form)
else:
form = UserForm()
def adherence_agreement(request, id):
item = get_object_or_404(UserInfo, pk=id)
return render(request, 'adherence_agreement.html', {'item': item})
{% extends "base.html" %}
{% load static %}
{% block content %}
<div class="container" id="printable">
<br>
<img src="{% static 'RDConnect_300dpi_RGB.jpg' %}" alt="" style="
display: block;
margin-left: auto;
margin-right: auto;
width: 60%;
"/>
<br>
<hr>
<h3>Adherence agreement for authorized access to data and biospecimens in the RD-Connect Genome-Phenome Analysis Platform (RDC-GPAP)<sup><a href="#fn1" id="ref1">1</a></sup><small class="text-muted"> to be used together with the <span class="text-info">Code of Conduct</span> for integrated user access to RDC-GPAP for health-related information and human biological samples.</small></h3>
<hr>
<h4>Effective as of 9<sup>th</sup> November 2015</h4>
<p>Communication to Mats G. Hansson, Centre for Research Ethics & Bioethics at Uppsala University: mats.hansson@crb.uu.se</p>
<hr>
<p>I, <span class="text-success">{{ item.first_name }} {{ item.last_name }}</span>, acting on behalf of the <span class="text-success">{{ item.department }}</span>, and holding the position <span class="text-success">{{ item.job_title }}</span>, herewith declare:</p>
<ol type="1">
<li>I have the authority to represent and engage the <span class="text-success">{{ item.department }}</span> for the purpose of the project, <span class="text-success">[project name]</span>. For this project we ask for access to data and/or biospecimens in accordance with our research interests as set out in our completed <span class="text-info">User Verification Form</span> (previous page).</li>
<br>
<li>The <span class="text-success">{{ item.department }}</span> agrees to fully endorse and adhere to the <span class="text-info">Code of Conduct</span> for integrated user access to the RDC-GPAP for health-related information and human biological samples, version 2, 3rd November 2017. It shall apply to all data and biospecimen processing activities carried out within the project <span class="text-success">[project name]</span>. The personal data protection framework is thus in part formalized through this Code.</li>
<br>
<li>The <span class="text-success">{{ item.department }}</span> will ensure the implementation of all measures required by the provisions of this Code.</li>
<br>
<li>The <span class="text-success">{{ item.department }}</span> will ensure compliance with this Code by all staff and personnel working within the project on behalf of the <span class="text-success">{{ item.department }}</span>.</li>
<br>
<li>In addition to the rules laid out by the Code, the following project specific rules shall apply:</li>
<br>
<ol type="a">
<li>There will be no attempt to try to identify or contact data or donor subjects.</li>
<li>Accessed data and biospecimens will not be redistributed.</li>
<li>Access codes and user logins are specific to the identified user and are strictly non-transferable.</li>
<li>Accessed datasets will be destroyed once they are no longer used.</li>
<li>Biospecimens will be handled in accordance with specifications in a Material Transfer Agreement.</li>
<li>Publications using any form of data accessed through the RDC-GPAP will contain an acknowledgment and a reference of the RDC-GPAP as appropriate.
Where a publication makes use of individual-level datasets and enriched phenotypic data, authors should consider whether the intellectual contribution of the original contributors of the datasets qualifies for authorship positions in line with standard publication practice.</li>
<li>Results of analyses of accessed data and biospecimens will be returned to the platform. Published work will also be sent to RD-Connect.</li>
<li>In case of misconduct access to the platform will be withdrawn.</li>
</ol>
</ol>
<hr>
<p>Signed on behalf of the <span class="text-success">{{ item.department }}</span> on <span class="text-success">{% now "jS F Y" %}</span> by <span class="text-success">{{ item.first_name }} {{ item.last_name }}</span>:</p>
<br>
<br>
<p>…………………………………………………</p>
<p>Signature</p>
<hr>
<sup id="fn1">1. This adherence agreement is based on the Personal Data Directive, Directive95/46/EC, implying that all personal data shall be handled in accordance with Secrecy law.<a href="#ref1" title="Jump back to footnote 1 in the text.">↩</a></sup>
<br>
<br>
</div>
<div class="container">
<input type="button" class="save btn btn-success btn-lg" onclick="printDiv('printable')" value="Print" />
<!-- <button id="printButton" class="save btn btn-success btn-lg">Print</button> -->
<br>
<br>
</div>
<script>
function printDiv(divName) {
var printContents = document.getElementById(divName).innerHTML;
var originalContents = document.body.innerHTML;
document.body.innerHTML = printContents;
window.print();
document.body.innerHTML = originalContents;
}
</script>
{% endblock %}
此时,单击“提交”按钮后,信息将正确保存到数据库中,并显示一个写有“谢谢”的基本页面(Thank.html
)。另外,如果我输入URLhttp://127.0.0.1:8000/userregistration/adherence_agreement/6
它将我带到一个页面,该页面包含从该记录中提取的特定字段(我根据数据库中的记录在URL中手动输入6)
遵守协议.html
:
from django.urls import path
from django.conf.urls import url, include
from django.views.generic import TemplateView
from .views import *
from . import views
urlpatterns = [
url(r'^$', UserView.as_view(), name='user_new.html'),
# form temporarily directs here after saving the data to the DB
url(r'^thanks/$', TemplateView.as_view(template_name='thanks.html'), name='thanks'),
# I would like it to go here instead
path('adherence_agreement/<int:id>', views.adherence_agreement, name='adherence_agreement'),
]
from django.views.generic.edit import FormView,CreateView
class UserView(CreateView):
template_name = 'user_new.html'
form_class = UserForm
success_url = 'thanks/'
def post(self, request, *args, **kwargs):
self.object = None
if request.method == 'POST':
form = UserForm(data=request.POST)
if form.is_valid():
form.save()
return self.form_valid(form)
else:
return self.form_invalid(form)
else:
form = UserForm()
def adherence_agreement(request, id):
item = get_object_or_404(UserInfo, pk=id)
return render(request, 'adherence_agreement.html', {'item': item})
{% extends "base.html" %}
{% load static %}
{% block content %}
<div class="container" id="printable">
<br>
<img src="{% static 'RDConnect_300dpi_RGB.jpg' %}" alt="" style="
display: block;
margin-left: auto;
margin-right: auto;
width: 60%;
"/>
<br>
<hr>
<h3>Adherence agreement for authorized access to data and biospecimens in the RD-Connect Genome-Phenome Analysis Platform (RDC-GPAP)<sup><a href="#fn1" id="ref1">1</a></sup><small class="text-muted"> to be used together with the <span class="text-info">Code of Conduct</span> for integrated user access to RDC-GPAP for health-related information and human biological samples.</small></h3>
<hr>
<h4>Effective as of 9<sup>th</sup> November 2015</h4>
<p>Communication to Mats G. Hansson, Centre for Research Ethics & Bioethics at Uppsala University: mats.hansson@crb.uu.se</p>
<hr>
<p>I, <span class="text-success">{{ item.first_name }} {{ item.last_name }}</span>, acting on behalf of the <span class="text-success">{{ item.department }}</span>, and holding the position <span class="text-success">{{ item.job_title }}</span>, herewith declare:</p>
<ol type="1">
<li>I have the authority to represent and engage the <span class="text-success">{{ item.department }}</span> for the purpose of the project, <span class="text-success">[project name]</span>. For this project we ask for access to data and/or biospecimens in accordance with our research interests as set out in our completed <span class="text-info">User Verification Form</span> (previous page).</li>
<br>
<li>The <span class="text-success">{{ item.department }}</span> agrees to fully endorse and adhere to the <span class="text-info">Code of Conduct</span> for integrated user access to the RDC-GPAP for health-related information and human biological samples, version 2, 3rd November 2017. It shall apply to all data and biospecimen processing activities carried out within the project <span class="text-success">[project name]</span>. The personal data protection framework is thus in part formalized through this Code.</li>
<br>
<li>The <span class="text-success">{{ item.department }}</span> will ensure the implementation of all measures required by the provisions of this Code.</li>
<br>
<li>The <span class="text-success">{{ item.department }}</span> will ensure compliance with this Code by all staff and personnel working within the project on behalf of the <span class="text-success">{{ item.department }}</span>.</li>
<br>
<li>In addition to the rules laid out by the Code, the following project specific rules shall apply:</li>
<br>
<ol type="a">
<li>There will be no attempt to try to identify or contact data or donor subjects.</li>
<li>Accessed data and biospecimens will not be redistributed.</li>
<li>Access codes and user logins are specific to the identified user and are strictly non-transferable.</li>
<li>Accessed datasets will be destroyed once they are no longer used.</li>
<li>Biospecimens will be handled in accordance with specifications in a Material Transfer Agreement.</li>
<li>Publications using any form of data accessed through the RDC-GPAP will contain an acknowledgment and a reference of the RDC-GPAP as appropriate.
Where a publication makes use of individual-level datasets and enriched phenotypic data, authors should consider whether the intellectual contribution of the original contributors of the datasets qualifies for authorship positions in line with standard publication practice.</li>
<li>Results of analyses of accessed data and biospecimens will be returned to the platform. Published work will also be sent to RD-Connect.</li>
<li>In case of misconduct access to the platform will be withdrawn.</li>
</ol>
</ol>
<hr>
<p>Signed on behalf of the <span class="text-success">{{ item.department }}</span> on <span class="text-success">{% now "jS F Y" %}</span> by <span class="text-success">{{ item.first_name }} {{ item.last_name }}</span>:</p>
<br>
<br>
<p>…………………………………………………</p>
<p>Signature</p>
<hr>
<sup id="fn1">1. This adherence agreement is based on the Personal Data Directive, Directive95/46/EC, implying that all personal data shall be handled in accordance with Secrecy law.<a href="#ref1" title="Jump back to footnote 1 in the text.">↩</a></sup>
<br>
<br>
</div>
<div class="container">
<input type="button" class="save btn btn-success btn-lg" onclick="printDiv('printable')" value="Print" />
<!-- <button id="printButton" class="save btn btn-success btn-lg">Print</button> -->
<br>
<br>
</div>
<script>
function printDiv(divName) {
var printContents = document.getElementById(divName).innerHTML;
var originalContents = document.body.innerHTML;
document.body.innerHTML = printContents;
window.print();
document.body.innerHTML = originalContents;
}
</script>
{% endblock %}
{%extends“base.html”%}
{%load static%}
{%block content%}
关于授权访问RD Connect基因组表型分析平台(RDC-GPAP)中的数据和生物样本的遵守协议,该平台将与用于健康相关信息和人类生物样本的RDC-GPAP综合用户访问行为准则一起使用。
自2015年11月9日起生效
与乌普萨拉大学研究伦理和生物伦理中心Mats G.Hansson的沟通:Mats。hansson@crb.uu.se
一、 {{item.first{u name}{{item.last{u name}},代表{{item.department},担任{{item.job{u title}职务,特此声明:
我有权代表{{item.department}参与项目,[项目名称]。对于本项目,我们要求根据我们的研究兴趣访问数据和/或生物样本,如我们填写的用户验证表(前页)中所述
{{item.department}}同意完全认可并遵守2017年11月3日第2版RDC-GPAP健康相关信息和人类生物样本综合用户访问行为准则。它应适用于在项目【项目名称】内进行的所有数据和生物样本处理活动。因此,个人数据保护框架部分通过本规范正式化
{{item.department}}将确保执行本守则规定的所有措施
{{item.department}将确保代表{{item.department}在项目内工作的所有员工和人员遵守本规范
除本规范规定的规则外,还应适用以下项目特定规则:
不会试图识别或联系数据或捐赠者受试者
访问的数据和生物样本将不会重新分发
访问代码和用户登录是特定于已识别用户的,并且严格不可转让
一旦不再使用,访问的数据集将被销毁
生物样品将按照材料转让协议中的规范进行处理
使用通过RDC-GPAP访问的任何形式的数据的出版物将包含RDC-GPAP的确认和参考(视情况而定)。
在出版物利用个体级数据集和丰富的表型数据的情况下,作者应该考虑数据集的原始贡献者的智力贡献是否符合作者发表位置的标准出版实践。
访问数据和生物样本的分析结果将返回平台。已发布的作品也将发送给RD Connect
如果出现不当行为,将撤销对平台的访问
{{item.first_name}{{item.last_name}代表{{{item.department}}在{%now“jS F Y”%}上签字:
签名
1.本遵守协议基于个人数据指令95/46/EC,这意味着所有个人数据均应按照保密法处理。
函数printDiv(divName){
var printContents=document.getElementById(divName).innerHTML;
var originalContents=document.body.innerHTML;
document.body.innerHTML=打印内容;
window.print();
document.body.innerHTML=原始内容;
}
{%endblock%}
您应该覆盖UserView
类的get\u success\u url
方法
def get_success_url(self):
return reverse('adherence_agreement', kwargs={'id': self.object.id})
是一个有用的网站,用于探索Django中基于类的通用视图的可重写方法您应该重写
UserView
类的get\u success\u url
方法
def get_success_url(self):
return reverse('adherence_agreement', kwargs={'id': self.object.id})
是一个有用的网站,用于探索Django中基于泛型类的视图的可重写方法