我正在开发发票管理系统,用户可以在其中添加发票数据并将其保存在数据库中,每当用户登录时,数据都会出现在主页上,但每当用户注销并尝试访问主页时,它都会出现以下错误。
TypeError at /
'AnonymousUser' object is not iterable
Run Code Online (Sandbox Code Playgroud)
我尝试了AnonymousUser.is_authenticated方法,但仍然无法正常工作。
我想如果用户登录然后home.html应该打开否则intro.html
这是我的代码 views.py
from django.shortcuts import render
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
from django.views.generic import (
ListView,
DetailView,
CreateView,
UpdateView,
DeleteView
)
from .models import Invoicelist
def home(request):
if request.user.is_authenticated():
context = {
'invoices': Invoicelist.objects.all()
}
return render(request, 'invoicedata/home.html', context)
else:
return render(request, 'invoicedata/intro.html', context)
Run Code Online (Sandbox Code Playgroud)
主页.html
{% extends "invoicedata/base.html" %}
{% block content %}
{% for invoice in invoices %}
<article class="media content-section">
<div class="media-body"> …Run Code Online (Sandbox Code Playgroud) 我想FileUpload在 jupyter 实验室中使用小部件。我的笔记本单元中有以下几行代码:
uploader = widgets.FileUpload()
uploader
Run Code Online (Sandbox Code Playgroud)
在 jupyter notebook 中,单元格的输出是一个可点击的按钮,我可以用它来上传文件。在 jupyter 实验室中,输出如下:
FileUpload(value={}, description='Upload')
Run Code Online (Sandbox Code Playgroud)
这是有关uploader对象的信息:
Type: FileUpload
String form: FileUpload(value={}, description='Upload')
File: ~/miniconda3/envs/fastai2/lib/python3.7/site-packages/ipywidgets/widgets/widget_upload.py
Run Code Online (Sandbox Code Playgroud)
是否可以让这个小部件在 jupyter 实验室上工作?如果是这样,我应该如何进行?
我正在尝试安装 jupyter-matplotlib 扩展,但无法使其在 jupyterlab 实例中工作。按照此处的步骤安装后:
https : //github.com/matplotlib/jupyter-matplotlib
执行简单示例时出现错误:
错误显示小部件:找不到模型

这是我$ conda list的相关包的输出:
ipykernel 5.1.1
ipympl 0.2.1
ipython 7.6.1
ipython_genutils 0.2.0
ipywidgets 7.5.0
jupyter_client 5.3.1
jupyter_core 4.4.0
jupyterlab 1.0.2
jupyterlab.0server 1.0
我有一个网站,www.a.com
在该网站中,我提供一个页面,其中https://www.a.com/mypage包含以下内容:
<script src='https://www.b.com/anotherpage'></script>
Run Code Online (Sandbox Code Playgroud)
如果我从每个浏览器访问,b.com都会收到以下 http 引用:
https://www.a.com/mypage
但是,如果我从 Safari 移动版或桌面版访问,引荐来源网址将变为:
https://www.a.com/
为什么?如何强制 Safari 发送完整的引荐来源网址?
例子:
来自 Safari、b.com 日志:
123.45.678.901 - - [06/Jun/2020:00:32:03 +0200] "GET /anotherpage/ HTTP/1.1" 200 0 "https://www.a.com/" "Mozilla/5.0 (iPhone; CPU iPhone OS 13_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1 Mobile/15E148 Safari/604.1"
Run Code Online (Sandbox Code Playgroud)
从另一个浏览器:
123.45.678.901 - - [06/Jun/2020:00:31:34 +0200] "GET /anotherpage/ HTTP/1.1" 200 0 "https://www.a.com/mypage/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36"
Run Code Online (Sandbox Code Playgroud)
我尝试添加这个:
<meta name="referrer" content="unsafe-url"> …Run Code Online (Sandbox Code Playgroud) 我想在演示文稿中添加一个文本框python pptx。我想在特定位置添加一个包含多个段落的文本框,然后对其进行格式化(字体、颜色等)。但由于文本形状对象总是在开头带有一个段落,因此我无法编辑第一个段落。代码示例如下所示:
txBox = slide.shapes.add_textbox(left, top, width, height)
tf = txBox.text_frame
p = tf.add_paragraph()
p.text = "This is a first paragraph"
p.font.size = Pt(11)
p = tf.add_paragraph()
p.text = "This is a second paragraph"
p.font.size = Pt(11)
Run Code Online (Sandbox Code Playgroud)
我可以使用 向第一行添加文本tf.text = "This is text inside a textbox",但它的字体或颜色不可编辑。那么有什么方法可以省略或编辑该行,以便框中的所有段落都相同?
我想打印一个非常非常接近 1 的浮点数,将其截断到小数点后两位而不进行四舍五入,最好使用尽可能少的代码。
a = 0.99999999999
print(f'{a:0.2f}')
Run Code Online (Sandbox Code Playgroud)
Expected: 0.99
Actual: 1.00
Run Code Online (Sandbox Code Playgroud) 我有一个文本文件(没有标点符号),文件大小约为 100MB - 1GB,这是一些示例行:
please check in here
i have a full hd movie
see you again bye bye
press ctrl c to copy text to clipboard
i need your help
...
Run Code Online (Sandbox Code Playgroud)
并带有替换令牌列表,如下所示:
check in -> check_in
full hd -> full_hd
bye bye -> bye_bye
ctrl c -> ctrl_c
...
Run Code Online (Sandbox Code Playgroud)
替换文本文件后我想要的输出如下:
please check_in here
i have a full_hd movie
see you again bye_bye
press ctrl_c to copy text to clipboard
i need your help
...
Run Code Online (Sandbox Code Playgroud)
please check in here …Run Code Online (Sandbox Code Playgroud) 我正在使用 nbconvert 将我的 jupyter notebook 转换为 html
jupyter nbconvert my.ipynb --to html
然后它说:
[NbConvertApp] 将 notebook my.ipynb 转换为 html [NbConvertApp] 将 407497 字节写入 my.html
然后在生成的my.html,我可以看到它需要custom.css:
<!-- Custom stylesheet, it must be in the same directory as the html file -->
<link rel="stylesheet" href="custom.css">
<!-- Loading mathjax macro -->
<!-- Load mathjax -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS_HTML"></script>
<!-- MathJax configuration -->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
processEscapes: true,
processEnvironments: …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Android Studio 构建一个旧项目,但该过程失败。我得到的错误信息是这样的:
错误:无法读取本机 JSON 数据使用 JsonReader.setLenient(true) 在第 1 行第 1 列路径处接受格式错误的 JSON
我相信应用程序的 build.gradle 文件是导致错误的原因。该文件的代码是:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.example.despoina.ldtest"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
ndk {
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
}
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
arguments '-DANDROID_PLATFORM=android-13',
'-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=gnustl_static'
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
// let gradle pack the …Run Code Online (Sandbox Code Playgroud) 是否有一种方法可以自动延迟所有Kubernetes pod 删除请求,以便发出端点注销信号,但 pod 的 SIGTERM 延迟几秒?
如果延迟仅影响具有端点/服务的 Pod,则更好,但不是必需的。
背景:
众所周知,由于端点注销和删除信号的异步特性,在 向Pod 发送 SIGTERM 终止信号后,某些流量可以继续流向 Pod 。建议的缓解措施是通过调用 来在 pod 的生命周期挂钩中引入几秒钟的延迟。preStopsleep
如果 pod 的部署可以通过 helm 或其他上游源完成,或者需要管理大量的部署和容器,那么困难很快就会出现。以这种方式修改许多部署可能很困难,甚至不可能(例如,容器可能没有睡眠二进制文件、shell 或除应用程序可执行文件之外的任何内容)。
我简要地探索了一个变异准入控制器,但这似乎无法动态添加preStop钩子,因为所有图像都没有/bin/sleep或已经有preStop可能需要特定于图像的知识来合并。
(当然,如果 K8S API 使端点注销与超时同步以避免死锁(提示,提示),那么所有这一切都可以避免,但我还没有看到任何关于此类更改的讨论。是的,有很多这是不同步的原因,但这并不意味着无法完成某些操作。)
我正在使用此代码来获取 youtube 频道的网址,它工作正常,但我想添加一个选项来搜索频道中具有特定标题的视频。并获取您使用搜索词组找到的第一个视频的网址
from bs4 import BeautifulSoup
import requests
url="https://www.youtube.com/feeds/videos.xml?user=LinusTechTips"
html = requests.get(url)
soup = BeautifulSoup(html.text, "lxml")
for entry in soup.find_all("entry"):
for link in entry.find_all("link"):
print(link["href"])
Run Code Online (Sandbox Code Playgroud) 我想创建一个 user_posts 视图,其中包含与特定用户相关的所有帖子,假设有用户“Natsu”撰写的博客帖子,那么登录用户“Testuser”将能够查看所有帖子由该用户即用户“Natsu”的所有帖子。
blog models.py
class Post(models.Model):
title = models.CharField(max_length=250)
slug = models.SlugField(max_length=250, unique_for_date='publish')
author = models.ForeignKey(User, on_delete=models.CASCADE, related_name='blog_posts')
body = models.TextField()
Run Code Online (Sandbox Code Playgroud)
user models.py
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
image = models.ImageField(upload_to='profile_pic', default='default.jpg')
def __str__(self):
return f'{ self.user.username } Profile'
Run Code Online (Sandbox Code Playgroud)
views.py
def user_posts(request, username):
posts = Post.objects.filter(author=username)
return render(request, 'blog/user_posts.html', {'posts':posts})
Run Code Online (Sandbox Code Playgroud)
user_posts.html
{% for post in posts %}
<a href="{% url 'user-posts' post.author.username %}" class="mr-2">{{ post.author }}</a>
<h2><a href="{% url 'post-detail' post.pk %}">{{ post.title }}</a></h2>
{{ post.body|truncatewords:30 }}
{% …Run Code Online (Sandbox Code Playgroud) python ×8
django ×2
android ×1
css ×1
deadlock ×1
decimal ×1
django-views ×1
f-string ×1
file-upload ×1
foreign-keys ×1
gradle ×1
html ×1
http ×1
http-referer ×1
json ×1
jupyter ×1
jupyter-lab ×1
kubernetes ×1
matplotlib ×1
nbconvert ×1
powerpoint ×1
python-pptx ×1
react-native ×1
safari ×1
sigterm ×1
tkinter ×1
token ×1
url ×1
valueerror ×1
web-scraping ×1
youtube ×1