使用django上传文件(uploading a file using django)
我正在使用django开发一个用于在服务器上上传文件的应用程序。 我已经在forms.py和models.py文件中分别定义了一个表单和模型,如下所示(分别):
from django import forms class DocumentForm(forms.Form): docfile = forms.FileField( label='' )
并在models.py中:
from django.db import models # Create your models here. class Document(models.Model): docfile = models.FileField(upload_to='targetdir')
在我的HTML文件中,我的表单是:
<form class="myclass" action="submit" method="post"> {% csrf_token %} <p> {{ form.docfile.errors }} {{ form.docfile }} </p> <br /> <input font-size="50px" style="zoom:1.5" class="myclass" dir="rtl" type="submit" value="upload" id="button" class="top-menu" onclick="pythonhandler()" />
现在,每当我提交表格,我想通过以下代码在服务器上接收我上传的文件时,我得到了“
raise MultiValueDictKeyError(repr(key)) MultiValueDictKeyError: "'docfile'""
错误。 我的views.py文件:
def pythonhandler(request): if request.method == 'POST': try: data = request.FILES.get('docfile') with open(os.getcwd()+'/mydirectory/'+request.FILES['docfile'].name, 'wb+') as destination: for chunk in request.FILES['docfile'].chunks(): destination.write(chunk)
I am developing an application with django for uploading a file on the server. I have defined a form and a model in forms.py and models.py files separately as below(respectively):
from django import forms class DocumentForm(forms.Form): docfile = forms.FileField( label='' )
and in models.py:
from django.db import models # Create your models here. class Document(models.Model): docfile = models.FileField(upload_to='targetdir')
in my HTML file and my form is:
<form class="myclass" action="submit" method="post"> {% csrf_token %} <p> {{ form.docfile.errors }} {{ form.docfile }} </p> <br /> <input font-size="50px" style="zoom:1.5" class="myclass" dir="rtl" type="submit" value="upload" id="button" class="top-menu" onclick="pythonhandler()" />
now, whenever I submit my form and I wanna to receive my uploaded file on the server via below codes, I got "
raise MultiValueDictKeyError(repr(key)) MultiValueDictKeyError: "'docfile'""
error. my views.py file:
def pythonhandler(request): if request.method == 'POST': try: data = request.FILES.get('docfile') with open(os.getcwd()+'/mydirectory/'+request.FILES['docfile'].name, 'wb+') as destination: for chunk in request.FILES['docfile'].chunks(): destination.write(chunk)
I did the mentioned steps in this , this and this question, but I receive this error again!
原文:https://stackoverflow.com/questions/43762485
最满意答案
Google Cloud DNS是权威的解析程序,即它会响应您拥有的区域的查询。 它不会递归到其他DNS名称,因此不能用于配置客户端。
谷歌还运行递归DNS解析器(不要与云DNS混淆): https : //developers.google.com/speed/public-dns/但是没有办法将其配置为返回贵公司的特殊结果或网络。
正如您所说,将查询重定向到safesearch的唯一真正方法是修改客户端使用的递归 DNS解析器。
(请参阅此处: https : //support.google.com/websearch/answer/186669?hl = zh_CN )
在这种情况下,我认为你最好的选择是将BIND递归至8.8.8.8,但使用手动RPZ进行安全搜索。
Google Cloud DNS is an authoritative resolver, i.e. it responds to queries for zones that you own. It will not recurse to other DNS names, so is no use for configuring clients.
Google also run a recursive DNS resolver, (not to be confused with Cloud DNS): https://developers.google.com/speed/public-dns/ but there is no way to configure this to return special results for your company or network.
As you say, the only real way to redirect queries to safesearch is via a modification to the recursive DNS resolver that your clients use.
(See here: https://support.google.com/websearch/answer/186669?hl=en)
In this case I think your best bet is to have BIND recurse to 8.8.8.8, but with a manual RPZ for safesearch.
相关问答
更多-
Google Cloud内部负载平衡器的内部DNS地址(Internal DNS address for Google Cloud internal load balancers)[2023-12-15]
GCE DNS元数据服务器中没有用于LB的条目。 https://issuetracker.google.com/issues/35904974上提供了一项开放功能请求。 您可以发送该请求来表明您的兴趣并订阅更新。 There is no entry in the GCE DNS metadata server for LBs. There is an open feature request for this at https://issuetracker.google.com/issues/359049 ... -
因此,您可以创建子域,因此您拥有: bar.foo.com但无法为foo.com/bar创建DNS记录。 输入CloudFlare,在CloudFlare中,您可以设置页面规则以将foo.com/bar重定向到bar.foo.com 。 您需要确保foo.com通过CloudFlare进行路由,并且在DNS设置中,云是橙色的。 然后,您需要确保bar.foo.com的DNS记录指向Google的服务器而不是您的cPanel。 玩的开心! I found the solution, it's basicall ...
-
Google云端DNS为您提供权威名称服务器,您可以使用DNS记录进行配置。 Google Public DNS只是一个名称解析器,用于查找来自权威名称服务器的数据。 有关权威名称服务器和缓存解析器的更多详细信息,请参见http://en.wikipedia.org/wiki/Name_server 。 是的,这个过程应该起作用。 Google Cloud DNS是您正在寻找的提供商的一个例子。 Google Cloud DNS provides you with authoritative name se ...
-
只需使用名称app.instance1domain.com为第二个实例创建A记录,并使用第二个GCE实例的IP地址。 如果要将第二个DNS受管区域转换为第一个 DNS 委托子区域,则需要一些额外的DNS记录,但您无需这样做即可在同一DNS受管区域中创建子域条目。 因此,单个托管区域可以包含以下所有条目: example.com xyz.example.com abc.xyz.example.com abc.def.example.com 在第四种情况下,您不需要为def.example.com创建条目,以便 ...
-
有关此方面的完整指南,请查看Google Cloud Platform in Action 。 您可以使用Cloud DNS API来注册实例,这非常简单。 我认为没有很好记录的部分是如何在启动脚本中获得正确的IP地址等。 以下代码片段在Node.js中有一些助手,用于下拉实例名称,区域和IP地址,然后您可以使用它们向Cloud DNS注册。 const request = require('request'); const metadataUrl = 'http://metadata.google.in ...
-
这似乎是一个已知问题,因为云DNS错误地报告了使用情况并影响了结算。 谷歌正致力于解决并恢复这些变化。 This seems to be a known issue with Cloud DNS incorrectly reporting usage and affecting the billing. Google are working on resolution and reverting these changes.
-
好的,我终于解决了这个问题。 在我的问题的屏幕截图中,需要进行以下更改。 1)将* .andtest.com.au的A记录替换为just和test.com.au的A记录 2)将www.andtest.com.au A记录替换为www.andtest.com.au的CNAME记录,该记录指向andtest.com 现在,当我在浏览器中输入www.andtest.com.au时,我会看到我的Tomcat网页。 OK, I finally worked out the problem. In the screen ...
-
在Gcloud计算引擎上,可以在此处找到有关自定义域的DNS配置的帮助: https://cloud.google.com/compute/docs/tutorials/setting-up-dns?hl=en On Gcloud compute engine, help on DNS configuration for custom domains can be found here: https://cloud.google.com/compute/docs/tutorials/setting-up-d ...
-
Google Cloud DNS是权威的解析程序,即它会响应您拥有的区域的查询。 它不会递归到其他DNS名称,因此不能用于配置客户端。 谷歌还运行递归DNS解析器(不要与云DNS混淆): https : //developers.google.com/speed/public-dns/但是没有办法将其配置为返回贵公司的特殊结果或网络。 正如您所说,将查询重定向到safesearch的唯一真正方法是修改客户端使用的递归 DNS解析器。 (请参阅此处: https : //support.google.com/ ...
-
Google Cloud DNS不会执行基于延迟的路由。 Cloud DNS名称服务器位于任播网络上,因此您的DNS查询将路由到“最近的”名称服务器。 请参阅https://cloud.google.com/dns/what-is-cloud-dns#performance_and_timing 。 但是,您的服务器的IP地址不在该网络上。 Google Cloud DNS does not do latency based routing. The Cloud DNS nameservers are on ...