简体   繁体   English

我们如何比较 django 中的请求 object?

[英]How can we compare request object in django?

I am building a website in django where user can upload their apk and the app will be modified by server and it return back the modified apk but there i have to limit user to upload 1 apk from 1 category at a time.我正在 django 中建立一个网站,用户可以在其中上传他们的 apk,该应用程序将由服务器修改并返回修改后的 apk,但我必须限制用户一次从 1 个类别上传 1 个 apk。

     if(request.FILES["app"]):
     name = request.FILES["app"]
    elif(request.FILES["lib"]):
      name = request.FILES["lib"]
    elif.... And more

But i am facing some multivalue dict key error anyone knows any better solution for this please suggest me.但是我面临一些多值字典键错误,任何人都知道对此有更好的解决方案,请建议我。

You can check if the key is present in the file with:您可以使用以下命令检查文件中是否存在密钥:

if 'app' in request.FILES:
    name = request.FILES['app']
elif 'lib' in request.FILES:
    name = request.FILES['lib']
# …

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 request.user 在 Django 中究竟返回了什么,我们可以将它与字符串进行比较吗? - what exactly does request.user return in django, can we compare it with a string? 我们可以在Django 1.9中将​​请求对象或关键字参数发送给m​​odelformset_factory吗 - Can we send a request object or keyword argument to modelformset_factory in django 1.9 我们可以在信号中获取请求对象数据吗 - Can we get the request object data in signal Python Numpy:我们如何比较 arrays? - Python Numpy: How can we compare arrays? Django的AuthenticationMiddlewear如何无法在请求中返回用户对象 - How can Django's AuthenticationMiddlewear not return a user object in the request Django:如何在管理面板中检测对象请求? - Django: How can i detect object request in admin panel? 我们可以从Django设置或其他变量中获取请求参数吗? - Can we get request parameters from Django settings or other variables? 如何使用 Django 比较 3 个日期? - How can I compare 3 dates using Django? how can we use more than one class object attributes of one model in another model in Django - how can we use more than one class object attributes of one model in another model in Django 我们如何在 django 中创建异步 API? - How can we create asynchronous API in django?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM