我正在将 django-two-factor-auth 用于网络应用程序。我无法访问管理页面。
我知道我输入了正确的凭据。当我输入不正确的凭据时,我会收到相应的错误消息。
当我输入正确的凭据时,页面会使用以下 URL 重新加载:
http://localhost:8080/account/login/?next=/inveskore/
Run Code Online (Sandbox Code Playgroud)
这些是我与two_factor相关的设置:
LOGIN_URL = 'two_factor:login'
LOGIN_REDIRECT_URL = '/inveskore'
TWO_FACTOR_SMS_GATEWAY = 'two_factor.gateways.twilio.gateway.Twilio'
Run Code Online (Sandbox Code Playgroud)
这是关联的 URL 路径:
LOGIN_URL = 'two_factor:login'
LOGIN_REDIRECT_URL = '/inveskore'
TWO_FACTOR_SMS_GATEWAY = 'two_factor.gateways.twilio.gateway.Twilio'
Run Code Online (Sandbox Code Playgroud)
据此,这是由于管理员用户没有设置 2FA 造成的。
那么,如果您无法访问该网站,如何为管理员用户设置 2FA?
编辑:
我删除了网站的 2FA 登录要求,然后添加了电话设备。没有运气。
python django django-admin two-factor-authentication django-two-factor-auth
我有一台运行 Linux 的 Docker 机器。我正在将 Pyomo 与 GLPK 求解器一起使用。我从 Docker 映像的 shell 命令行安装了 GLPK,使用apt-get install glpk-utils
我所有的代码都保存在子文件夹下 /code
我可以看到glpsol安装在路径下:/usr/bin
我可以看到这/usr/bin是 PATH 环境变量下的路径。
我有相关的进口如下:
from pyomo.environ import *
from pyomo.opt import SolverFactory
Run Code Online (Sandbox Code Playgroud)
当我运行时opt = SolverFactory("glpk"),出现以下错误:
Attempting to use an unavailable solver.
The SolverFactory was unable to create the solver "glpk"
and returned an UnknownSolver object. This error is raised at the point
where the UnknownSolver object was used as if it were valid …Run Code Online (Sandbox Code Playgroud) 在 python-docx 中处理表格。我试图对表格的第一行与其余行应用不同的样式。这将是标题行。这是表格:
table2 = doc.add_table(rows=10, cols=3)
heading_cells_table2 = table2.rows[0].cells
heading_cells_table2[0].text = 'Header 1'
heading_cells_table2[1].text = 'Header 2'
heading_cells_table2[2].text = 'Header 3'
Run Code Online (Sandbox Code Playgroud)
我希望我能做这样的事情:
table2.rows[0].style = table_heading_style
Run Code Online (Sandbox Code Playgroud)
我尝试了 .add_run()、.cells、.font、.text 等的许多其他变体和组合,但没有成功。
是否可以更改表格中单个单元格/行/列的格式?如果是这样,是如何做到的?
谢谢您的帮助。
编辑
对于这个问题的答案的具体示例,以下是我最终如何将文本集中在表格中 3 列中的 2 列中,这要感谢 scanny 的帮助。
for column in itertools.islice(table2.columns, 1, 3):
for cell in column.cells:
for paragraph in cell.paragraphs:
paragraph.paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER
Run Code Online (Sandbox Code Playgroud) Django 新手
所以这个可能有一个非常简单的答案,但我一生都找不到具体的解决方案。我只是想在使用 FileField 提交表单后重定向到新的 URL。
我可以单独导航到该 URL,效果很好。
文件上传正确,因此我知道它已正确验证。
但重定向返回以下错误:
Reverse for 'success' not found. 'success' is not a valid view function or pattern name.
Run Code Online (Sandbox Code Playgroud)
我尝试了很多不同的命名约定,但没有一个有效。在我看来,我已经设置了 URL 并正确传递了它。
非常感谢对此的一些帮助。最简单的问题却是最令人沮丧的!
以下是观点。
from django.shortcuts import render, redirect
from django.http import HttpResponse, HttpResponseRedirect
from django.urls import reverse
from .forms import InvestmentReportForm
def upload(request):
if request.method == 'POST':
form = InvestmentReportForm(request.POST, request.FILES)
if form.is_valid():
form.save()
return redirect('success')
else:
form = InvestmentReportForm()
return render(request, 'app/upload.html', {'form': form})
def success(request):
return HttpResponse("File successfully uploaded")
Run Code Online (Sandbox Code Playgroud)
还有我的 urls.py: …
我正在尝试在 PyCharm 中的 Python 3.5 中运行 Reportlab 3.4
我通过项目解释器安装(并且我也通过终端安装)。当我尝试导入以下包时
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter
from reportlab.lib.pagesizes import portrait
from reportlab.platypus import Image
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
ImportError: No module named 'reportlab.pdfgen'; 'reportlab' is not a package
Run Code Online (Sandbox Code Playgroud)
几年前似乎有几个人遇到过这个问题,但我找不到最近发生这种情况的例子。
任何见解将不胜感激。
在django测试中使用Client时,是否有快速方法从表单提交中获取错误?
这是一段代码片段:
with open(good_path) as fp:
data = {
'account': account_id,
'date': date,
'file': fp
}
response = client.post(reverse('myapp:form-page'), data)
Run Code Online (Sandbox Code Playgroud)
页面没有正确重定向(响应= 200),我可以看到response.content返回错误.
是否有快速隔离错误的方法?我希望有response.errors类似的东西,类似于表单实例.
django ×3
python ×3
django-admin ×1
docker ×1
forms ×1
glpk ×1
installation ×1
post ×1
pyomo ×1
python-docx ×1
redirect ×1
reportlab ×1
testing ×1