python初学者在这里有一个简单的问题。一直在使用 Python-Docx 从 Python 数据(从 Excel 表格生成)生成一些 word 报告。到目前为止一切顺利,但想根据相关数据向 Word 文档添加几个图表。我看过 pandas 和 matplotlib ,似乎它们都可以很好地满足我的需要(只有几个条形图,没什么疯狂的)。但是谁能告诉我是否可以在python中创建图表并通过docx将其输出到word文档?
我正在用 python 创建一个工作日志,用户可以在其中输入任务或按日期查找任务。我的初始提示要求用户输入任务或按日期查找。如果用户首先按日期查找,则程序将正常工作并显示所有日期。如果用户首先添加任务,然后按日期查找任务,则程序会显示“对象不支持索引错误”。我认为由于某种原因,该列表正在被清空,但我一生都无法理解这种情况可能在何时何地发生。这是主要工作日志文件:
import csv
import re
import datetime
from task import Task
from task_list import TaskList
class Worklog():
def __init__(self):
self.filename = "work_log.csv"
self.tasklist = TaskList()
self.tasklist.read_task_from_file(self.filename)
def search_by_date(self):
for d, i in enumerate(self.tasklist.dates()):
print(d+1, ':', i)
# while True:
# datereq = input("Select Number To See Tasks For A Date").strip().lower()
# try:
# datereq = int(datereq)
# return datereq
# except ValueError:
# print("Invalid Entry. Please try again")
# continue
def search_by_time(self):
pass
def exact_search(self):
pass
def pattern_search(self): …Run Code Online (Sandbox Code Playgroud) 我在 Heroku 上有一个 Django 站点,使用 Dnsimple 来管理 DNS。我还使用 Django 强制使用 HTTPS。
我正在尝试遵循 google 协议,以便我只有一个域
https://example.com
这样,如果用户访问http://www.example.com或https://www.example.com
它会重定向到https://example.com
我在 Dnsimple 中的设置如下所示:
ALIAS example.com example.com.herokudns.com
CNAME www.example.com example.com.herokudns.com
Run Code Online (Sandbox Code Playgroud)
我尝试删除 cname 并在 Dnsimple 中使用 URL 重定向,但它不起作用。
执行此重定向的正确方法是什么?我尝试根据另一个过时的帖子创建一个中间件,但它使我的网站崩溃了。
我的网站运行良好,但后来我上传到 Heroku 的图像开始出现问题。我在 Django 中使用白噪声,但决定将我的图像存储和静态文件移动到 AWS。我一直在学习本教程,并且能够将我的静态文件夹中的文件获取到 S3。
但是现在我在尝试部署到 Heroku 时遇到了问题。
注意我static的 app 文件夹中有一个文件夹,在 root 内。
推送时出现此错误 - 其中包括 collectstatic
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/build_f05a3a5f9e4b6ad44dfdf0b62dd16e9e/static'
我很确定它是 Heroku (?) 的临时存储区,但我猜 /static 不应该放在最后。
我将在这里复制我的相关 settings.py 变量:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
DEFAULT_FILE_STORAGE = 'dealmazing.storage_backends.MediaStorage'
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles')
# Additional locations of static files
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]
#This will make sure that the file URL does not have unnecessary parameters …Run Code Online (Sandbox Code Playgroud) 我有一个个人资料页面,我希望允许用户上传个人资料图片.我可以编辑所有文本,但无法上传图像.如果我通过管理员添加图像,但不通过网站上的用户个人资料页面,它可以工作.请注意,通过管理员创建时 - 它正确上传到我在媒体文件夹中指定的目录(profile_image).我在模板页面上创建了一些错误处理,但生成的错误是:"'image'属性没有与之关联的文件." 以下是我的代码:
models.py
class UserProfile(models.Model):
user = models.OneToOneField(User)
first_name = models.CharField(default='',max_length=100 )
last_name = models.CharField(default='',max_length=100)
email = models.CharField(max_length=100, default='')
date_birth = models.DateField(default=datetime.datetime.now())
bio = models.TextField(default='')
image = models.ImageField(upload_to='profile_image', blank=True)
def create_profile(sender, **kwargs):
if kwargs['created']:
user_profile = UserProfile.objects.create(user=kwargs['instance'])
post_save.connect(create_profile, sender=User)
Run Code Online (Sandbox Code Playgroud)
views.py
@login_required
def edit_profile(request):
profile = get_object_or_404(models.UserProfile)
if request.method == 'POST':
form = forms.EditProfileForm(data=request.POST, instance=profile)
if form.is_valid():
form.save()
return redirect('/accounts/profile')
else:
form = forms.EditProfileForm(instance=profile)
args = {'form':form}
return render(request, 'accounts/edit_profile.html', args)
Run Code Online (Sandbox Code Playgroud)
forms.py
from django import forms
from django.contrib.auth.models import …Run Code Online (Sandbox Code Playgroud) 考虑到Django是为新闻网站构建的,我正在尝试做一些我认为相对简单的事情。只是想获取按年/月计数分组的存档列表,位于我的博客的侧边栏上。就像是
2018
-Mar(3)
-Feb (2)
-Jan (6)
Run Code Online (Sandbox Code Playgroud)
我在这里进行了很多搜索,但是似乎已经过去了一段时间,因为有人想要做这样的事情,而其他一切都已经过时了。
我已经能够弄清楚如何创建每月存档的url / view / tempate,并且可以通过转到blog/2018/03 这里是我博客的观点来显示一个月的帖子
class BlogListView(generic.ListView):
model = Post
context_object_name = 'post_list'
queryset = Post.objects.all()
template_name = 'post_list.html'
class ArticleMonthArchiveView(MonthArchiveView):
queryset = Post.objects.all()
date_field = "posted"
allow_future = True
def blog_post(request, slug):
blog_post = Post.objects.get(slug=slug)
context = {'blog_post': blog_post}
return render(request, 'blog/blog_post.html', context)
Run Code Online (Sandbox Code Playgroud)
和我的网址(请暂时忽略网址和路径的混合-可以解决!)
urlpatterns = [
url(r'^$', BlogListView.as_view(), name='blog'),
url(r'^(?P<slug>[\w-]+)/$', blog_post, name='blog_post'),
path('<int:year>/<int:month>/',
ArticleMonthArchiveView.as_view(month_format='%m'),
name="post_archive_month"),
]
Run Code Online (Sandbox Code Playgroud)
我想我需要在所有视图上创建另一个上下文字段,以便执行此操作?但是我真的不知道从哪里开始。我知道我显然可以手动创建一个月列表并循环查看是否匹配帖子,但我无法想象这是最有效的方法。
任何人都有一个很明显的解决方案,我可能在这里不见了?
我正在研究 Jquery 中学生列表的搜索功能,虽然我可以获得正确的结果以打印到控制台,但结果没有出现在页面上。匹配时,我在控制台中收到以下错误。我只是不确定我在选择器上声明 listStudents 变量的方式是否有问题?是不是不可能在这样的选择器数组上运行 each 函数?我难住了。
Uncaught TypeError: listName.each is not a function
at showPage (main.js:10)
at searchList (main.js:92)
at HTMLButtonElement.<anonymous> (main.js:54)
Run Code Online (Sandbox Code Playgroud)
下面是我的 JS 文件
var listStudents = $(".student-list").children();
var numStudents = listStudents.length;;
function showPage(pageNum, listName) {
// first hide all students on the page
$(".student-list li").hide();
pageNum = parseInt(pageNum);
// Then loop through all students in our student list argument
listName.each(function(index){
// if student should be on this page number
if ((index >= ((pageNum*10)-10)) && (index <= (pageNum*10))) …Run Code Online (Sandbox Code Playgroud) 我有一个显示卡片列表的组件。我正在尝试对表格行进行排序,但遇到了一些问题。当我转到页面时,出现以下错误:
错误:重新渲染过多。React 限制渲染次数以防止无限循环。
它指向这条线
setData(_.sortBy(filteredData.reverse()));
Run Code Online (Sandbox Code Playgroud)
这是我的完整组件代码。任何人都可以看到我正在尝试做的事情有问题吗?
import React, { useState } from "react";
import Search from "./Search";
import TimeAgo from "react-timeago";
import { useSelector, useDispatch, connect } from "react-redux";
import { Table } from "semantic-ui-react";
import { searchChange } from "../reducers/searchReducer";
import _ from "lodash";
// import { useField } from "../hooks";
const searchCards = ({ baseball, search }) => {
return search
? baseball.filter(a =>
a.title[0].toLowerCase().includes(search.toLowerCase())
)
: baseball;
};
const Cards = props => {
const [column, setColumn] …Run Code Online (Sandbox Code Playgroud) django ×4
python ×4
heroku ×2
javascript ×2
dns ×1
dnsimple ×1
excel ×1
indexing ×1
jquery ×1
lodash ×1
matplotlib ×1
python-docx ×1
react-redux ×1
reactjs ×1
redirect ×1