本文整理匯總了Python中django.shortcuts.render_to_response方法的典型用法代碼示例。如果您正苦於以下問題:Python shortcuts.render_to_response方法的具體用法?Python shortcuts.render_to_response怎麽用?Python shortcuts.render_to_response使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.shortcuts
的用法示例。
在下文中一共展示了shortcuts.render_to_response方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: form_detail
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import render_to_response [as 別名]
def form_detail(request, slug, template="forms/form_detail.html"):
form = get_object_or_404(models.DocumentSetForm, slug=slug)
request_context = RequestContext(request)
args = (form, request_context, request.POST or None)
form_for_form = forms.DocumentSetFormForForm(*args)
if request.method == 'POST':
if not form_for_form.is_valid():
form_invalid.send(sender=request, form=form_for_form)
return HttpResponseBadRequest(json.dumps(form_for_form.errors), content_type='application/json')
else:
entry = form_for_form.save()
form_valid.send(sender=request, form=form_for_form, entry=entry, document_id=request.session['document_id_for_entry'])
return HttpResponse('')
return render_to_response(template, { 'form': form }, request_context)
示例2: choose_current_organization
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import render_to_response [as 別名]
def choose_current_organization(request):
""" Show which Organizations can be selected """
organizations = request.user.organization_set.all()
current_organization = None
try:
user_profile = request.user.get_profile()
except models.UserProfile.DoesNotExist:
user_profile = models.UserProfile(user=request.user, name=request.user.get_full_name())
user_profile.save()
if user_profile:
current_organization = user_profile.current_organization
template = 'choose_current_organization.html' if organizations.count() > 0 else 'without_organization.html'
return render_to_response(template, {
'organizations': organizations,
'current_organization': current_organization,
'organization_signup_link': settings.ORGANIZATION_SIGNUP_LINK
},
context_instance = RequestContext(request))
示例3: render_select_site_form
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import render_to_response [as 別名]
def render_select_site_form(self, request, context, form_url=''):
"""
Render the site choice form.
"""
app_label = self.opts.app_label
context.update({
'has_change_permission': self.has_change_permission(request),
'form_url': mark_safe(form_url),
'opts': self.opts,
'add': True,
'save_on_top': self.save_on_top,
})
return render_to_response(self.select_site_form_template or [
'admin/%s/%s/select_site_form.html' % (app_label, self.opts.object_name.lower()),
'admin/%s/select_site_form.html' % app_label,
'admin/usersettings/select_site_form.html', # added default here
'admin/select_site_form.html'
], context)
示例4: index
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import render_to_response [as 別名]
def index(request):
if request.method == 'POST':
form = PathAnalysisForm(request.POST)
if form.is_valid():
query = form.cleaned_data['search']
print(query)
#here is where the magic happens!
#search in kegg
# data = kegg_rest_request('list/pathway/hsa')
# pathways = kegg_rest_request('find/pathway/%s' % (query))
pathways = Pathway.objects.filter(Q(name__icontains=query))
# print pathways
else:
form = PathAnalysisForm()
# pathways = kegg_rest_request('list/pathway/hsa')
pathways = Pathway.objects.all()
return render_to_response('pathway_analysis/index.html', {'form': form, 'pathways': pathways}, context_instance=RequestContext(request))
示例5: index
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import render_to_response [as 別名]
def index(request):
offline_register(request)
if request.user.is_authenticated():
request.session['username'] = request.user.username
request.session['uid'] = request.user.pk
else:
request.session['uid'] = -1
print(">>>>>>>", request.session.get('newdump'));
# if request.session.get('newdump'):
# dumpid = request.session.get('newdump')
# return render(request,'index.html',context={"dump":dumpid})
return render_to_response("index.html", locals(), context_instance=RequestContext(request))
# contex = {
# "request":RequestContext(request),
# "dump":dumpid
# }
# return render(request,'index.html',contex)
示例6: process_detail
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import render_to_response [as 別名]
def process_detail(request):
context = {}
try:
if request.POST.get("setPid") and request.POST.get("setDumpid"):
context = {
"pid": request.POST.get("setPid"),
"dumpid": request.POST.get("setDumpid"),
"dumpname": request.POST.get("dumpName")
}
else:
raise Exception("No Process Id or Dump Id Specified")
except Exception as ex:
raise Exception(ex)
return render_to_response("singleprocess.html", context, context_instance=RequestContext(request))
示例7: detail
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import render_to_response [as 別名]
def detail(self, request):
'''
查看用戶的ansible的option數據
'''
result = self._is_login(request)
if result[0] :
username = result[1]
else :
return HttpResponseRedirect(reverse('login'))
vault_password = request.session['vault_password']
result = self.ansible_option_api.detail(username, vault_password)
if result[0] :
data = result[1]
error_message = ''
self.logger.info(self.username + ' 查看用戶' + username + '的ansible配置成功')
else :
data = {}
error_message = self.username + ' 查看用戶' + username + '的ansible配置失敗,查詢時發生錯誤,原因:' + result[1]
self.logger.error(error_message)
error_message = result[1]
return render_to_response('option_detail.html', {'data':data, 'login_user':username, 'error_message':error_message, 'nav_html':self.nav_html, 'lately_whereabouts':self.latelywhere_html})
示例8: generic_composition_view
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import render_to_response [as 別名]
def generic_composition_view(request, search=None):
data = {'search':search}
composition = ''
space = []
if request.method == 'POST':
p = request.POST
search = p.get('search', '')
data.update(p)
if not search:
return render_to_response('materials/generic_composition.html',
data,
RequestContext(request))
gc = GenericComposition(search)
data['gc'] = gc
return render_to_response('materials/generic_composition.html',
data,
RequestContext(request))
示例9: journal_view
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import render_to_response [as 別名]
def journal_view(request, journal_id):
journal = Journal.objects.get(id=journal_id)
dates = journal.references.values_list('year', flat=True)
plt.hist(dates)
plt.xlabel('Year')
plt.ylabel('# of publications with new materials')
img = StringIO.StringIO()
plt.savefig(img, dpi=75, bbox_inches='tight')
data_uri = 'data:image/jpg;base64,'
data_uri += img.getvalue().encode('base64').replace('\n', '')
plt.close()
some_entries = Entry.objects.filter(reference__journal=journal)[:20]
data = get_globals()
data.update({'journal':journal,
'hist':data_uri,
'entries':some_entries})
return render_to_response('data/reference/journal.html',
data,
RequestContext(request))
示例10: author_view
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import render_to_response [as 別名]
def author_view(request, author_id):
author = Author.objects.get(id=author_id)
materials = Entry.objects.filter(reference__author_set=author)
coauths = {}
for co in Author.objects.filter(references__author_set=author):
papers = Reference.objects.filter(author_set=author)
papers = papers.filter(author_set=co)
mats = Entry.objects.filter(reference__in=papers)
data = {'papers': papers.distinct().count(),
'materials': mats.distinct().count()}
coauths[co] = data
data = get_globals()
data.update({'author':author,
'materials':materials,
'coauthors':coauths})
return render_to_response('data/reference/author.html',
data,
RequestContext(request))
示例11: search
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import render_to_response [as 別名]
def search(request):
d = RequestContext(request, {})
return render_to_response("search.html", d)
示例12: feature_detail
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import render_to_response [as 別名]
def feature_detail(request, id):
feature = get_object_or_404(Feature, pk=id)
geojson = json.dumps(feature.get_geojson())
d = RequestContext(request, {
'feature': feature,
'geojson': geojson
})
return render_to_response("feature.html", d)
示例13: index
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import render_to_response [as 別名]
def index(request):
places_count = Place.objects.count("*")
context = RequestContext(request, {
'total_count': places_count
})
return render_to_response("index.html", context)
示例14: edit_place
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import render_to_response [as 別名]
def edit_place(request, place_id):
place = get_place_or_404(place_id)
geojson = json.dumps(place.to_geojson())
context = RequestContext(request, {
'place': place,
'place_geojson': geojson
})
return render_to_response("edit_place.html", context)
示例15: module_handler
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import render_to_response [as 別名]
def module_handler(request):
"""
Handle module request from UI. Response from this request builds
UI Explorer tree
"""
logger.debug("module_handler: enter")
lst = []
if request.user.is_authenticated():
path = request.GET.get('node', '')
deep = request.GET.get('deep', '')
username = request.user.username
if path == 'root':
# Request for root models
modules = ModuleAdmin.get_modulelist(username)
modules.sort()
for m in modules:
lst.append(node_t.format(m.split('@')[0]))
else:
modules = [path.split('/')[0]]
for module in modules:
filename = ModuleAdmin.cxml_path(username, module)
if filename is not None:
logger.debug("module_handler: loading " + filename)
module = cxml.get_cxml(filename)
nodes = module.get_lazy_subtree(path, deep)
lst.extend([ET.tostring(node) for node in annotate(nodes)])
else:
logger.error("module_handler: %s not found !!" + module)
logger.debug("module_handler: exit")
return render_to_response('loader.xml', {'nodes': lst}, RequestContext(request))