小编Ral*_*alf的帖子

如何直接在浏览器中打开pdf文件?

我想PDF直接在浏览器中查看文件.我知道这个问题已经被问到了,但我找不到适用于我的解决方案.

到目前为止,这是我的动作控制器代码:

public ActionResult GetPdf(string fileName)
{
    string filePath = "~/Content/files/" + fileName;
    return File(filePath, "application/pdf", fileName);
}
Run Code Online (Sandbox Code Playgroud)

这是我的观点:

@{
   doc = "Mode_d'emploi.pdf";
} 

<p>@Html.ActionLink(UserResource.DocumentationLink, "GetPdf", "General", new { fileName = doc }, null)</p>
Run Code Online (Sandbox Code Playgroud)

当我鼠标悬停时,这里的链接是链接:

在此输入图像描述

我的代码的问题是pdf文件没有在浏览器中查看,但我收到一条消息,询问我是否打开或保存文件.

在此输入图像描述

我知道这是可能的,我的浏览器支持它,因为我已经用另一个网站测试它,允许我pdf直接在我的浏览器中查看.

例如,这是我鼠标悬停链接(在另一个网站上)时的链接:

在此输入图像描述

如您所见,生成的链接存在差异.我不知道这是否有用.

知道怎样才能pdf直接在浏览器中查看我的内容?

c# asp.net-mvc

19
推荐指数
3
解决办法
5万
查看次数

如何在PySpark中存储?

例如,我想DataFrame根据年龄将一个人分为以下4个箱子.

age_bins = [0, 6, 18, 60, np.Inf]
age_labels = ['infant', 'minor', 'adult', 'senior']
Run Code Online (Sandbox Code Playgroud)

我会pandas.cut()用来做这个pandas.我该怎么办PySpark

pyspark

17
推荐指数
2
解决办法
7556
查看次数

Spring Boot 2.0.0,在autoconfigure jar中找不到DataSourceBuilder

我们正在将现有的Spring Boot (1.5)应用程序升级到2.0.0.

我们连接多个数据库并使用org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder该类.

我添加了依赖:

compile group: 'org.springframework.boot',
name: 'spring-boot-autoconfigure',
version: '2.0.0.RELEASE' 
Run Code Online (Sandbox Code Playgroud)

但是,我无法编译项目:此类(DataSourceBuilder)在2.0.0版本jar中不存在.

为了排除gradle问题,我手动下载了jar并将其添加到了classpath.该类在版本中不存在.

还提取并搜索了jar但这个类缺失了.任何人都可以帮我解决吗?

spring-boot

16
推荐指数
1
解决办法
1万
查看次数

django.db.utils.IntegrityError:外键约束失败

我的模型.py

\n\n
class Order(models.Model):\n    user = models.ForeignKey(User, blank=True, null=True, on_delete=models.PROTECT)\n    customer_email = models.EmailField(blank=True, null=True, default=None)\n    customer_name = models.CharField(max_length = 64, blank=True, null=True, default=None)\n    customer_phone = models.CharField(max_length = 48, blank=True, null=True, default=None)\n    customer_address = models.CharField(max_length = 128, blank=True, null=True, default=None)\n    total_price = models.DecimalField(max_digits=10, decimal_places=2, default=0) #total price for all products in order\n    comments = models.TextField(blank=True, null=True, default=None)\n    status = models.ForeignKey(Status, on_delete=models.PROTECT)\n    created = models.DateTimeField(auto_now_add=True, auto_now=False)\n    updated = models.DateTimeField(auto_now_add=False, auto_now=True)\n\n    def __str__(self):\n        return "\xd0\x97\xd0\xb0\xd0\xba\xd0\xb0\xd0\xb7 %s %s" % (self.id, self.status.name)\n\n    class Meta:\n …
Run Code Online (Sandbox Code Playgroud)

python django foreign-keys django-models django-views

11
推荐指数
1
解决办法
3万
查看次数

PgAdmin错误:无法解密保存的密码

将我的pgAdmin版本更新为之后,V4-4.8我将无法再登录数据库。我正在尝试登录Windows 10

错误:

Failed to decrypt the saved password.
Error: 'utf-8' codec can't decode byte 0xc3 in position 0: invalid continuation byte
Run Code Online (Sandbox Code Playgroud)

postgresql pgadmin

10
推荐指数
1
解决办法
1568
查看次数

无法从__future__导入注释

运行语句时

from __future__ import annotations
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Traceback (most recent call last):
  File "/usr/lib/python3.5/py_compile.py", line 125, in compile
    _optimize=optimize)
  File "<frozen importlib._bootstrap_external>", line 735, in source_to_code
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "./prog.py", line 1
    from __future__ import annotations
    ^
SyntaxError: future feature annotations is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.5/py_compile.py", line 129, in compile
    raise py_exc
py_compile.PyCompileError:   File "./prog.py", line …
Run Code Online (Sandbox Code Playgroud)

python import future python-3.x

9
推荐指数
1
解决办法
5034
查看次数

403 石墨烯-django。不要使用 csrf_exempt

我用graphene-django。创建一个应用程序,GraphiQL对于登录和其他功能运行良好。但是当我使用时Insomnia,我收到403 Forbidden错误。

我参考了这个文档, https://github.com/howtographql/howtographql/blob/master/content/backend/graphql-python/4-authentication.md

我尝试过:

  1. 使用csrf_exempt; 它工作得很好,但我当然不会使用它。
  2. 使用django-cors-headers; 它不好用。

我该如何解决这个403错误?

django graphql

8
推荐指数
2
解决办法
4039
查看次数

为什么Anaconda不建议设置path环境变量

Anaconda3 5.3.0 64bit

在安装过程中,我选中了在 PATH 环境变量中添加 Anaconda 的选项。那么它不建议我这样做。它说:

相反,请使用 Windows“开始”菜单打开 Anaconda,然后选择“Anaconda(64 位)”。此“添加到 PATH”选项使 Anaconda 在以前安装的软件之前找到,但可能会导致问题,要求您安装并重新安装 Anaconda。

它到底意味着什么?我想将其添加到 PATH 中,因为我也想通过命令行界面进行工作,但我不希望出现问题。

python anaconda

8
推荐指数
1
解决办法
9188
查看次数

Django 连接自动轮换密码数据库

我有一个Django运行完美的应用程序。它连接到MySQL云上托管的服务器。

出于安全原因,服务器MySQL设置为每 30 天自动轮换一次密码。仅当使用我开发的自定义函数(将从中获取新密码)加载Django时才能访问新密码。settings.pyAWS Secrets Manager

我正在寻找一种方法来检测Django连接是否有问题,然后更新对用户完全透明的密码。

那可能吗?

python mysql passwords django

7
推荐指数
1
解决办法
1004
查看次数

在 Python 3 中将字典列表转换为 CSV

我得到了不同长度甚至不同(key: values)对的字典列表。例如:

[
    {'key1': 'value1', 'key3':'value3'},
    {'key1': 'someValue', 'key2':'value2', 'key3':'value3'},
    {'anotherKey': 'anotherValue', 'key1': 'value1', 'key2':'value2'},
    {'anotherKey': 'anotherValue', 'anotherKey1': 'anotherValue1', 'key1': 'value1', 'key2':'value2', 'key3':'value3'},
]
Run Code Online (Sandbox Code Playgroud)

我需要创建CSV所有键作为标题和值的文件。如果键不在当前字典中,则设置默认值(例如“-”)。在CSV从例子应该寻找这样的:

在此处输入图片说明

我正在为我的字典列表尝试此代码,但它返回一个错误:

listOfDicts = [
    {'key1': 'value1', 'key3':'value3'},
    {'key1': 'someValue', 'key2':'value2', 'key3':'value3'},
    {'anotherKey': 'anotherValue', 'key1': 'value1', 'key2':'value2'},
    {'anotherKey': 'anotherValue', 'anotherKey1': 'anotherValue1', 'key1': 'value1', 'key2':'value2', 'key3':'value3'},
]

keys = listOfDicts[0].keys()
with open('test.csv', 'a') as output_file:
    dict_writer = csv.DictWriter(output_file, fieldnames=keys, delimiter='@')
    dict_writer.writeheader()
    dict_writer.writerows(listOfDicts)
Run Code Online (Sandbox Code Playgroud)

错误:

ValueError: dict contains fields not in fieldnames: 'key2' …
Run Code Online (Sandbox Code Playgroud)

python csv dictionary list python-3.x

7
推荐指数
1
解决办法
4385
查看次数