我试图了解它是如何asyncio工作的。在我的场景中,客户端与服务器建立tcp连接,发送登录字符串(如果经过身份验证)-接收字符流。最后将字符串KeyboardInterrupt发送logoff到服务器并愉快地断开连接。
目前,我陷入了最后一部分,因为我的注销方法/任务在有机会完成之前就被破坏了。
^CTask was destroyed but it is pending!
source_traceback: Object created at (most recent call last):
File "tst.py", line 101, in <module>
client.login()
File "tst.py", line 29, in login
logoff_tsk = self.loop.create_task(self.logoff())
task: <Task pending coro=<logoff() running at tst.py:49> cb=[myClass._shutdown()] created at tst.py:29>
Run Code Online (Sandbox Code Playgroud)
下面是产生此错误的代码:
from functools import partial
import asyncio
class myClass:
def __init__(self, *a, **kw):
self.transport = None
self.protocol = None
self.usr = str(kw.get("usr", ""))
self.pwd = str(kw.get("pwd", ""))
self.host …Run Code Online (Sandbox Code Playgroud) 我正在查看wagtail hello-world 表单
示例:
class FormField(AbstractFormField):
page = ParentalKey('FormPage', related_name='form_fields')
class FormPage(AbstractEmailForm):
landing_page_template = 'blog/form_page.html'
intro = RichTextField(blank=True)
thank_you_text = RichTextField(blank=True)
content_panels = AbstractEmailForm.content_panels + [
FormSubmissionsPanel(),
FieldPanel('intro', classname="full"),
InlinePanel('form_fields', label="Form fields"),
FieldPanel('thank_you_text', classname="full"),
MultiFieldPanel([
FieldRowPanel([
FieldPanel('from_address', classname="col6"),
FieldPanel('to_address', classname="col6"),
]),
FieldPanel('subject'),
], "Email"),
]
Run Code Online (Sandbox Code Playgroud)
如果给出这样的模板:
{% for field in form %}
{{ field }}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
它将呈现类似于以下内容的 HTML:
<input type="text" name="label1" value="Default Label1" required maxlength="255" id="id_label1" />
<input type="url" name="label2" value="http://Label2.net" id="id_label2" />
<textarea name="label3" required rows="10" …Run Code Online (Sandbox Code Playgroud) bytes因此,我收到的数据是我需要类似文件的临时容器。据我所知BytesIO是类似文件的对象,但json.load()不适用于它:
In [1]: import json
...: from io import BytesIO, TextIOWrapper
In [2]: d, b = dict(a=1, b=2), BytesIO()
In [3]: b.write(json.dumps(d).encode())
Out[3]: 16
In [4]: b.seek(0)
Out[4]: 0
In [5]: b.read()
Out[5]: b'{"a": 1, "b": 2}'
In [6]: b.seek(0)
Out[6]: 0
In [7]: json.load(b)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-7-233ac51d2711> in <module>()
----> 1 json.load(b)
/usr/lib/python3.5/json/__init__.py in load(fp, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
266 cls=cls, object_hook=object_hook, …Run Code Online (Sandbox Code Playgroud) 我尝试遵循Vuetify 网站上的CDN 使用示例,但出现以下错误:
[Vue warn]: 未知的自定义元素:
<v-list-tile>- 您是否正确注册了组件?对于递归组件,请确保提供“名称”选项。
[Vue warn]: 未知的自定义元素:<v-list-tile-action>- 您是否正确注册了组件?对于递归组件,请确保提供“名称”选项。
[Vue warn]: 未知的自定义元素:<v-list-tile-content>- 您是否正确注册了组件?对于递归组件,请确保提供“名称”选项。
请参阅codepen中的示例。
new Vue({
el: '#app',
vuetify: new Vuetify(),
data: {
drawer: false,
app_title: 'Custom Name...',
elevations: [6, 12, 24],
tiles: [4,5,6,7,8,9]
},
})
Run Code Online (Sandbox Code Playgroud)
<div id="app">
<v-navigation-drawer
v-model="drawer"
temporary
fixed
app
>
<v-list dense>
<v-list-tile @click="">
<v-list-tile-action>
<v-icon>home</v-icon>
</v-list-tile-action>
<v-list-tile-content>
<v-list-tile-title>Home</v-list-tile-title>
</v-list-tile-content>
</v-list-tile>
<v-list-tile @click="">
<v-list-tile-action>
<v-icon>contact_mail</v-icon>
</v-list-tile-action>
<v-list-tile-content>
<v-list-tile-title>Report</v-list-tile-title>
</v-list-tile-content>
</v-list-tile>
</v-list>
</v-navigation-drawer> …Run Code Online (Sandbox Code Playgroud) python ×2
cdn ×1
django ×1
django-forms ×1
javascript ×1
python-3.4 ×1
python-3.x ×1
vue.js ×1
vuejs2 ×1
vuetify.js ×1
wagtail ×1