小编sam*_*idi的帖子

在 Django 中使用基于异步类的视图的正确方法

我正在尝试使用非常新的Django 3.1Async 视图类。基于可用的有限文档,我尝试创建自己的async def __call__()方法。从文件:

对于基于类的视图,这意味着将其__call__()方法设为 an async def(而不是它的__init__()as_view())。

Django 3.1 开发文档

但是,到目前为止,我还没有编写基于异步类的视图。我经常收到await异常或asyncio.iscoroutinefunction返回False,如果该类实际上是异步的,我认为应该返回 true。

由于文档缺少示例,有更多异步编程知识的人可以帮助我提供基于类的异步视图示例吗?

django async-await python-asyncio

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

Docker-compose 无法导入 Django (ModuleNotFoundError)

我对 Docker 很陌生,我一直在尝试让一个非常简单的“Hello World”程序在 docker 上运行。无论我做什么,我总是得到:

ModuleNotFoundError:没有名为“Django”的模块

我究竟做错了什么?

这是终端输出。

C:\path\to\app\root>docker-compose up
Creating network "hello-world_default" with the default driver
Creating hello-world_web_1 ... done                                                                                     Attaching to hello-world_web_1
web_1  | Traceback (most recent call last):
web_1  |   File "/code/manage.py", line 10, in main
web_1  |     from django.core.management import execute_from_command_line
web_1  | ModuleNotFoundError: No module named 'django'
web_1  |
web_1  | The above exception was the direct cause of the following exception:
web_1  |
web_1  | Traceback (most recent call last):
web_1  |   File …
Run Code Online (Sandbox Code Playgroud)

python django docker dockerfile docker-compose

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

为什么我的Python函数不会执行?

我很擅长编码.我写了一段简单的代码,它将URL作为输入,加载URL并将该URL的状态代码放在变量中.我把它放在一个函数中.但是,当我运行代码时,我没有错误,但函数将无法运行.似乎翻译只是飞过我的功能.我知道我有一些简单的错误,但无论我搜索多少都无法修复它.请帮我理解.哦,代码不完整.但该功能应该运行.

import urllib.request, click, threading

url = input("Enter domain name >> \n")

def get_stat():
    status = urllib.request.urlopen("http://"+url).getcode()
    if status == 200:
        return "Site loads normally!\nHost Said: '%s'!" %(str(status))
    else:
        return "Site Needs To Be Checked!\nHost Said: '%s'!" %(str(status))
get_stat()

if click.confirm("Would you like to set a uptime watch?"):
    click.echo("You just confirmed something!!")
    count = input("Enter the number of times you wish your site to be checked: ")
    interval = input("Enter the time interval for status requests (Time is in minutes): …
Run Code Online (Sandbox Code Playgroud)

python function

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