小编Che*_*che的帖子

在django中处理单个html表单的多个输入值

我有一个带有3个输入和步骤按钮的html表单.

  • 1 步用户必须把名字和按下按钮1
  • 2 第二步骤,用户必须把最后一个名称,然后按按钮2
  • 3 第三步,用户必须把电子邮件,并按下按钮,最后3

每当用户按下任何按钮,然后转到下一个html步骤.

我希望views.py在用户按任何按钮的任何时候逐步处理输入,而不是在最终提交中一起处理输入.

我尝试使用此代码在views.pydjango后端获取输入,但我没有得到任何东西views.py(如果我更改按钮类型button,submit然后我得到结果坚果刷新页面,我不能转到第2步)

views.py

if request.method == 'POST' and 'first_step' in request.POST:
    print '1'
    firstname= request.POST.get('firstname')
if request.method == 'POST' and 'second_step' in request.POST:
    print '2'
    lastname= request.POST.get('lastname')
if request.method == 'POST' and 'final_step' in request.POST:
    print '3'
    email= request.POST.get('email')
Run Code Online (Sandbox Code Playgroud)

这是我的HTML代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">

    <title>Form wizard with circular tabs</title>

    <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
</head> …
Run Code Online (Sandbox Code Playgroud)

html javascript python django django-views

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

模块未找到错误:office365 未找到

我已经通过一些解决方案看到了这个问题,但没有一个解决我的问题。office365(v 2.2.0)据我所知,我已经使用以下命令pip 安装了最新版本:

pip install office365-rest-client
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用以下代码行进行导入:

    from office365.runtime.auth.authentication_context import AuthenticationContext
    from office365.sharepoint.client_context import ClientContext
    from office365.sharepoint.files.file import File
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

ModuleNotFoundError: No module named 'office365'
Run Code Online (Sandbox Code Playgroud)

为了测试一下,我卸载并重新安装了 pandas,然后成功将 pandas 导入到我的项目中。

python sharepoint module pip office365

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

如何在 GraphQL 中表达输入验证

我想知道如何在 GraphQL 架构中表达输入类型验证,例如:

input DateFormat {
  format: String!
}
Run Code Online (Sandbox Code Playgroud)
  • 我该如何表达format最多 10 个字符,例如其他验证。
  • 这可以使用GraphQL-core 3 for python 来实现吗?

提前致谢

python python-3.x graphql graphql-python

6
推荐指数
1
解决办法
1361
查看次数

没有模块名为fake useragent

我正在尝试使用PyTrendsGithub上提供的模块(这里).要使用此脚本,我需要安装fake-useragent模块:

pip install fake-useragent
Run Code Online (Sandbox Code Playgroud)

但是,每次我导入文件并尝试在控制台中执行命令时,我都会收到以下错误:

>>> from pytrends2.pyGTrends import pyGTrends
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pytrends2.py", line 18, in <module>
    from fake_useragent import UserAgent
ImportError: No module named fake_useragent
Run Code Online (Sandbox Code Playgroud)

我尝试了不同的东西,没有运气.尝试确保安装依赖项模块时:

pip install pyyaml ua-parser user-agents
Run Code Online (Sandbox Code Playgroud)

......我得到以下内容:

abraham@abraham-Inspiron-3521:~$ sudo pip install pyyaml user-agents
Downloading/unpacking pyyaml
  Downloading PyYAML-3.11.tar.gz (248kB): 248kB downloaded
  Running setup.py (path:/tmp/pip_build_root/pyyaml/setup.py) egg_info for package pyyaml

Downloading/unpacking user-agents
  Downloading user_agents-1.0.1-py2-none-any.whl
Downloading/unpacking ua-parser (from user-agents)
  Downloading ua_parser-0.5.0-py2-none-any.whl (66kB): 66kB downloaded …
Run Code Online (Sandbox Code Playgroud)

python

5
推荐指数
1
解决办法
6174
查看次数

Python:具有对象列表的对象 - 基于列表成员的属性创建方法

我有一个包含如下列表的类:

class Zoo:
    def __init__(self):
        self._animals = []
Run Code Online (Sandbox Code Playgroud)

我使用具有各种属性的动物对象填充动物列表:

class Animal:
    def __init__(self, speed, height, length):
        self._speed = speed
        self._height = height
        self._length = length
Run Code Online (Sandbox Code Playgroud)

您可以想象具有其他属性的Animal的子类.我希望能够编写执行相同计算但在Animal的不同属性上的方法.例如,平均值.我可以在Zoo中编写以下内容:

def get_average(self, propertyname):
    return sum(getattr(x, propertyname) for x in self.animals) / len(self.animals)
Run Code Online (Sandbox Code Playgroud)

那个字符串查找不仅仅是因为我能够很好地记录,但是使用getattr看起来很奇怪(也许我只是紧张地传递字符串?).如果这是一个很好的标准做法,那很好.创建get_average_speed(),get_average_height()get_average_length()方法,特别是当我添加更多属性时,似乎也是不明智的.

我意识到我试图在这个例子中封装一个单行程序,但是有没有更好的方法来根据Zoo列表中对象的属性创建这样的方法?我看了一下工厂的功能,所以当我更好地理解它们时,我想我可以这样写:

all_properties = ['speed', 'height', 'length']
for p in all_properties:
    Zoo.make_average_function(p)
Run Code Online (Sandbox Code Playgroud)

然后动物园的任何实例都会有所谓的方法get_average_speed(),get_average_height()以及get_average_length(),最好有好的文档字符串.更进一步,我真的很喜欢Animal对象本身告诉我的动物园什么属性可以变成get_average()方法.最后,让我说我是Animal的子类,并希望它表明它创建了一个新的平均方法:( 以下是伪代码,我不知道装饰器是否可以像这样使用)

class Tiger(Animal):
    def __init__(self, tail_length):
        self._tail_length = tail_length

    @Zoo.make_average_function
    @property
    def tail_length(self): …
Run Code Online (Sandbox Code Playgroud)

python attributes list object python-3.x

5
推荐指数
1
解决办法
117
查看次数

如何重新启动heroku应用程序而不杀死未完成的celery任务

我在 Heroku 上有一个 Django Web 应用程序,其中多个 celery 任务可能在后台运行。Redis 用作代理。

问题是,当我在执行某些任务时使用heroku restart或通过部署重新启动heroku应用程序时,它们会被SIGTERM杀死,这意味着任务永远不会完成。heroku container:release

2018-11-23T19:35:24.506833+00:00 heroku[beat.1]: Restarting
2018-11-23T19:35:24.507645+00:00 heroku[beat.1]: State changed from up to starting
2018-11-23T19:35:24.517551+00:00 heroku[web.1]: Restarting
2018-11-23T19:35:24.518013+00:00 heroku[web.1]: State changed from up to starting
2018-11-23T19:35:24.528684+00:00 heroku[worker.1]: Restarting
2018-11-23T19:35:24.529175+00:00 heroku[worker.1]: State changed from up to starting
2018-11-23T19:35:24.952139+00:00 app[worker.1]: 
2018-11-23T19:35:24.952156+00:00 app[worker.1]: worker: Warm shutdown (MainProcess)
2018-11-23T19:35:24.949622+00:00 heroku[worker.1]: Stopping all processes with SIGTERM
2018-11-23T19:35:24.996307+00:00 heroku[worker.1]: Process exited with status 143
2018-11-23T19:35:25.456920+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2018-11-23T19:35:25.480748+00:00 app[web.1]: [2018-11-23 …
Run Code Online (Sandbox Code Playgroud)

python django heroku celery

5
推荐指数
1
解决办法
1229
查看次数

如何在具有不同动态DJANGO_SETTINGS_MODULE环境变量的同一服务器上运行两个Django应用

I'm running two django application in same server. Server setup and multi settings file are created.

But I have DJANGO_SETTINGS_MODULE env variable as dynamic and I need to set two different values.

If I change DJANGO_SETTINGS_MODULE variable name to something else, i'm getting error.

Can anyone suggest some solution for this problem.

django environment-variables django-rest-framework

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

POST 请求是否缓存在 Django 中?

我想根据发送给它的 POST 数据来缓存一些视图。

装饰器会django.views.decorators.cache.cache_page自动执行此操作还是我需要以某种方式调整它?对于后一种情况,我该怎么办?

我正在尝试缓存 GraphQL POST 请求。

django django-cache graphql

0
推荐指数
1
解决办法
833
查看次数