本文整理汇总了Python中shortcuts.render函数的典型用法代码示例。如果您正苦于以下问题:Python render函数的具体用法?Python render怎么用?Python render使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了render函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: home
def home(request):
"""Home page"""
articles = get_qs_for_user(request.user)
events = Event.objects.filter(date__gte=datetime.today())
if request.user.has_perm('website.add_event'):
request.user.can_add_event = True
return render(request, 'website/home.html', locals())
开发者ID:brutasse-archive,项目名称:webeleves,代码行数:7,代码来源:views.py
示例2: directory
def directory(request, mbox_id, page=1):
mbox_id = int(mbox_id)
page = int(page)
total = Thread.objects(mailboxes=mbox_id).count()
begin = (page - 1) * 50
end = min(total, begin + 50)
threads = Thread.objects(mailboxes=mbox_id)[begin:end]
# Filter with user profile to be sure you are looking at your mails !
# TODO Replace account's id with something more fashion
directory = request.user.get_profile().get_directory(mbox_id)
context = {
'directory': directory,
'threads': threads,
'begin': begin + 1,
'end': end,
'total': total,
}
if total > end:
context['next_url'] = reverse('directory',
args=[mbox_id, page+1])
if page > 1:
context['previous_url'] = reverse('directory',
args=[mbox_id, page-1])
return render(request, 'mail.html', context)
开发者ID:brutasse-archive,项目名称:wombat,代码行数:26,代码来源:views.py
示例3: login
def login(request):
user = User()
if request.method == 'GET':
if 'login-user' in request.session:
user = request.session['login-user']
return render(request, 'login.html', {'user':user})
if request.method == "POST":
try:
user = User.objects.get(email=request.POST['email'],
password=hashlib.sha1(request.POST['password']).hexdigest())
except:
pass
if not user.id:
user.email = request.POST['email']
user.errors = ['invalid-login']
request.session['login-user'] = user
return redirect('/login')
user.last_login = datetime.datetime.now()
user.save()
request.session["USER_ID"] = user.id
if 'login-user' in request.session:
del request.session['login-user']
if 'version' in request.session:
del request.session['version']
return redirect('/')
开发者ID:follower76,项目名称:DPT,代码行数:25,代码来源:account.py
示例4: inbox
def inbox(request, account_slug=None, page=1):
page = int(page)
profile = request.user.get_profile()
accounts = profile.accounts.all()
if account_slug is not None:
accounts = [accounts.get(slug=account_slug)]
if not accounts:
messages.info(request, _('You don\'t have any account yet, please '
'fill in the form below'))
return redirect(reverse('add_account'))
inboxes = Mailbox.objects.filter(imap__account__in=accounts,
folder_type=INBOX).values_list('id',
flat=True)
total = Thread.objects(mailboxes__in=inboxes).count()
begin = (page - 1) * 50
end = min(total, begin + 50)
threads = Thread.objects(mailboxes__in=inboxes)[begin:end]
directory = profile.get_directory(inboxes[0])
context = {
'unified': True,
'directory': directory,
'threads': threads,
'begin': begin + 1,
'end': end,
'total': total,
}
if total > end:
context['next_url'] = reverse('inbox', args=[page+1])
if page > 1:
context['previous_url'] = reverse('inbox', args=[page-1])
return render(request, 'mail.html', context)
开发者ID:brutasse-archive,项目名称:wombat,代码行数:34,代码来源:views.py
示例5: add_account
def add_account(request):
if request.method == 'POST':
account_form = AccountForm(data=request.POST)
smtp_form = SMTPForm(data=request.POST, prefix='smtp')
imap_form = IMAPForm(data=request.POST, prefix='imap')
if all([form.is_valid() for form in (account_form,
smtp_form,
imap_form)]):
# Create an Account, attach it an IMAP and an SMTP instance.
account = account_form.save(commit=False)
account.profile = request.user.get_profile()
account.imap = imap_form.save()
account.smtp = smtp_form.save()
account.save()
messages.success(request, _('Your account has been successfully '
'created'))
return redirect(reverse('edit_account', args=[account.id]))
else:
account_form = AccountForm()
smtp_form = SMTPForm(prefix='smtp')
imap_form = IMAPForm(prefix='imap')
context = {
'account': account_form,
'imap': imap_form,
'smtp': smtp_form
}
return render(request, 'users/add_account.html', context)
开发者ID:brutasse-archive,项目名称:wombat,代码行数:27,代码来源:views.py
示例6: main
def main(request):
if not request.user.is_authenticated():
return redirect(reverse('registration_register'))
# if 'version' in request.session:
# version = request.session['version']
# print "Taking Version from Session"
# else:
# print "Taking Version from DB"
try:
version = Version.objects.filter()[0]
except IndexError:
version = Version(date=datetime.datetime.now())
version.save()
a = [[], [], [], []]
if version:
products = Product.objects.filter(version=version, selectable=True)
for i in range(products.count() / 4):
a[0].append(products[4 * i])
a[1].append(products[4 * i + 1])
a[2].append(products[4 * i + 2])
a[3].append(products[4 * i + 3])
products = a
# global Big_Matrix
# Big_Matrix = eval(BigMatrix.objects.get(version = version).matrix)
# Big_Matrix = dpt2Matrix.Big_Matrix
# changing to custom page to test- change from main.html to dinestart.html
return render(request, 'main.html', {'products': products, 'version': version})
开发者ID:follower76,项目名称:DPT,代码行数:27,代码来源:views.py
示例7: edit_account
def edit_account(request, id):
account = get_object_or_404(Account, id=id)
if request.method == 'POST':
account_form = AccountForm(data=request.POST, instance=account)
smtp_form = SMTPForm(data=request.POST, prefix='smtp',
instance=account.smtp)
imap_form = IMAPForm(data=request.POST, prefix='imap',
instance=account.imap)
if all([form.is_valid() for form in (account_form, smtp_form,
imap_form)]):
account_form.save()
imap_form.save()
smtp_form.save()
messages.success(request, _('Your account have been successfully'
' updated.'))
return redirect(reverse('accounts'))
else:
account_form = AccountForm(instance=account)
smtp_form = SMTPForm(prefix='smtp', instance=account.smtp)
imap_form = IMAPForm(prefix='imap', instance=account.imap)
context = {
'account': account,
'account_form': account_form,
'imap': imap_form,
'smtp': smtp_form
}
return render(request, 'users/edit_account.html', context)
开发者ID:brutasse-archive,项目名称:wombat,代码行数:29,代码来源:views.py
示例8: preferences
def preferences(request):
try:
rnd = Round.objects.filter(user=request.user).order_by('-id')[0]
except IndexError:
return redirect('/')
polls = Poll.objects.select_related().filter(round=rnd).order_by('-id')
if not polls:
return redirect('/start')
poll = polls[0]
return render(request, 'preferences.html', {'poll':poll})
开发者ID:follower76,项目名称:DPT,代码行数:10,代码来源:m_views.py
示例9: random_meal
def random_meal(request): #reinier
# if 'version' in request.session:
# version = request.session['version']
# else:
try:
version = Version.objects.order_by('-id')[0]
except IndexError:
return redirect('/')
products = Product.objects.filter(version=version)
output = len(products)
random_num = random.randint(1, len(products) - 1)
meal = products[random_num]
return render(request, 'random_meal.html', {'versions': versions, 'output': output, 'meal': meal})
开发者ID:follower76,项目名称:DPT,代码行数:13,代码来源:views.py
示例10: login_screen
def login_screen(self, request):
vars = {"form_field_name": self.form_field_name, "path": request.get_full_path(), "error": {}}
check = self.rate_limit_manual(request)
if check:
return check
if request.method == "POST":
password = request.POST.get(self.form_field_name, "")
if password:
if password == self.get_password():
response = http.HttpResponseRedirect(request.get_full_path())
self.set_cookie(response, password)
return response
else:
self.cache_incr(self.current_key(request))
vars["error"]["pw"] = "That is not the correct password."
email = request.POST.get("ebygum", "")
if email:
if email_re.match(email):
obj = Prelaunch(email=email)
obj.save()
vars["messages"] = ["Thank you; you will hopefully hear from us in the not too distant future."]
else:
vars["error"]["em"] = "Please enter a valid email address."
statuses = [
"Painting scenery",
"Auditioning actors",
"Cutting out gobos",
"Rehearsing",
"Measuring for costumes",
"Learning lines",
"Stocking the ice-cream cabinet",
]
rand_not = int(request.POST.get("not", 0))
if rand_not >= 1 and rand_not <= 7:
rand = random.randint(0, len(statuses) - 2)
if rand >= rand_not:
rand += 1
else:
rand = random.randint(0, len(statuses) - 1)
vars["rand"] = rand
vars["status"] = statuses[rand]
return render(request, "alpha_password.html", vars)
开发者ID:dracos,项目名称:Theatricalia,代码行数:47,代码来源:middleware.py
示例11: results
def results(request, page=None):
if 'version' in request.session:
version = request.session['version']
else:
try:
version = Version.objects.order_by('-id')[0]
except IndexError:
return redirect('/')
rnd = Round.objects.filter(user=request.user).order_by('-id')[0]
results = Result.objects.filter(round=rnd)
property_ids = [x.id for x in Property.objects.filter(version=version)]
function_ids = [r.function_id for r in results]
function_properties = FunctionProperty.objects.select_related().filter(function__id__in=function_ids).values_list('function_id', 'property_id', 'value')
properties = {}
for p in property_ids:
properties[p] = 0
for p in function_properties:
properties[p[1]] += p[2]
for i in properties.keys():
properties[i] /= len(function_ids)
products = Product.objects.filter(version=version)
product_properties = ProductProperty.objects.select_related().filter(product__in=products).values_list('product_id', 'property_id', 'value')
p_coefficients = {}
for p in products:
p_coefficients[p.id] = {}
for c in product_properties:
p_coefficients[c[0]][c[1]] = c[2]
products = products.values()
for product in products:
score = 0
for property_id in property_ids:
score += properties[property_id] * p_coefficients[product['id']][property_id]
product['score'] = score
products = sorted(products, key=lambda k: k['score'])
products.reverse()
pages = []
for i in range(len(products) / 8):
pages.append(products[8 * i:8 * i + 8])
products = products[:8]
polls = Poll.objects.filter(round=rnd)
return render(request, 'results.html', {'results':results, 'products':products, 'polls':polls, 'pages':pages})
开发者ID:follower76,项目名称:DPT,代码行数:47,代码来源:m_views.py
示例12: settings
def settings(request):
profile = request.user.get_profile()
if request.method == 'POST':
form = ProfileForm(request.POST, instance=profile)
if form.is_valid():
form.save()
messages.success(request, _('Your settings have been updated'))
return redirect(reverse('default_inbox'))
else:
# TODO: handle correctly the error and translate the message
err = "Incorrect config..."
else:
err = ''
form = ProfileForm(instance=profile)
context = {'user': request.user, 'form': form,}
return render(request, 'settings.html', context)
开发者ID:brutasse-archive,项目名称:wombat,代码行数:17,代码来源:views.py
注:本文中的shortcuts.render函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论