我正在尝试Service Worker
在测试页面中实现一个.我的最终目标是离线操作的应用程序.文件夹结构如下
/myApp
...
/static
/mod
/practice
service-worker.js
worker-directives.js
foopage.js
/templates
/practice
foopage.html
Run Code Online (Sandbox Code Playgroud)
我正在注册服务工作者,如下所示(内service-worker.js
):
navigator.serviceWorker.register('../static/mod/practice/service-worker.js').then(function(reg) {
console.log('Registration succeeded. Scope is ' + reg.scope);
...
}
Run Code Online (Sandbox Code Playgroud)
在控制台中,我看到了
Registration succeeded. Scope is https://example.com/static/mod/practice/
如果我的页面位于https://example.com/practice/foopage
,我是否需要确保我的service worker
范围是https://example.com/practice/foopage
?
如果我尝试在register
函数调用中定义范围,如
navigator.serviceWorker.register('../static/mod/practice/service-worker.js', { scope: '/practice/foopage/' }).then(function(reg) {
...
}
Run Code Online (Sandbox Code Playgroud)
我收到了错误
Registration failed with SecurityError: Failed to register a ServiceWorker: The path of the provided scope ('/practice/foopage/') is not under the max scope allowed ('/static/mod/practice/'). Adjust …
Run Code Online (Sandbox Code Playgroud) 我的webapp导航系统中有一个表,每次呈现页面时都会填充最新信息.我怎么能避免在每个代码中加入以下代码view
?
def myview():
mydict = code_to_generate_dict()
return render_template('main_page.html',mydict=mydict)
Run Code Online (Sandbox Code Playgroud)
mydict
用于填充表格.该表将显示在每个页面上
如果我有一个SQLAlchemy声明模型如下所示:
class Test(Model):
__tablename__ = 'tests'
id = Column(Integer, Sequence('test_id_seq'), primary_key=True)
...
Atest_id = Column(Integer, ForeignKey('Atests.id'), nullable=True)
Btest_id = Column(Integer, ForeignKey('Btests.id'), nullable=True)
Ctest_id = Column(Integer, ForeignKey('Ctests.id'), nullable=True)
Dtest_id = Column(Integer, ForeignKey('Dtests.id'), nullable=True)
Etest_id = Column(Integer, ForeignKey('Etests.id'), nullable=True)
...
date = Column(DateTime)
status = Column(String(20)) # pass, fail, needs_review
Run Code Online (Sandbox Code Playgroud)
我想确保*test_id
在给定的行中只有一个外键存在,我该如何实现SQLAlchemy
呢?
我看到有一个SQLAlchemy
CheckConstraint
对象(参见docs),但MySQL
不支持检查约束.
数据模型之外有交互SQLAlchemy
,因此最好是数据库级别的检查(MySQL
)
我的SQLAlchemy模型有一个String
字段,我想限制为几个选择.
我想知道如何在Flask-Admin界面中为此字段创建一个下拉列表,以确保只使用我的一个选项填充数据库.如果我让用户手动输入这些字段,他们可能会错误地拼写它们等.
我有一个观察者,应该每隔X秒完成一次动作.X的值动态变化.我一直无法绕过如何在运行时动态更改此间隔.根据我的理解,我的想法中的一个重大突破是Observables一旦被定义就无法改变,所以尝试用新的区间值重新定义Observalbe似乎不是正确的方法.
我一直在尝试使用位于https://www.learnrxjs.io/operators/transformation/switchmap.html的代码.
到目前为止,我认为这switchMap
至少是在正确的轨道上.有人能够提供一个例子或指向我可能对我有用的资源吗?
至少,世界肯定需要更多的RxJs例子!
我们正在使用一个非常古老的程序来驱动一些设备测试.这些测试可以运行几天,我想知道测试何时完成.当测试完成时,可执行文件会以每秒约1次的蜂鸣声连续发出主板扬声器的蜂鸣声,直到操作员干预.
有没有办法可以"听"这个嘟嘟声并在MB开始发出哔哔声时发出通知?我希望有一个sys
或os
库可以用来表明这一点.
我们在Windows XP x86上运行.我还没有在机器上安装Python.
伪代码:
already_beeping = True
while True:
speaker_beeping = check_speaker() # returns True or False
if speaker_beeping == True:
if already_beeping == False:
send_notification()
already_beeping = True
else:
pass
else:
already_beeping = False
time.sleep(10)
Run Code Online (Sandbox Code Playgroud) 我输入的打印语句多于代码.这太痛苦了.
如果通过下面调用烧瓶开发服务器,我可以使用PyCharm调试器
from ersapp import app
if __name__ == '__main__':
app.run(debug=True)
Run Code Online (Sandbox Code Playgroud)
我在Miguel Grinberg的书中遵循了这个例子,并使用了一个应用程序管理器(flask-script).我在我的应用程序目录中调用服务器,如下所示
(env)$ python manage.py runserver
Run Code Online (Sandbox Code Playgroud)
并在 appdirectory/__init__.py
def create_app(config_name):
webapp = Flask(__name__)
...
return webapp
Run Code Online (Sandbox Code Playgroud)
Pycharm中的调试器会让事情变得更容易,因为那是我工作的地方.
我无法解决这个文件的工作原理.我似乎在每个例子中看到它.见下文:
server {
listen 80;
server_name sivusto3.fi;
access_log /var/log/customersite3/access_log;
location / {
root /var/www/customersite3;
uwsgi_pass 127.0.0.1:3033;
include uwsgi_params;
}
}
Run Code Online (Sandbox Code Playgroud) 我遇到以下逻辑问题:
让我们说我有一个清单 L = ['a', 'b', 'c']
这两个项目都在列表中......
if ('a' or 'b') in L:
print 'it\'s there!'
else:
print 'No sorry'
Run Code Online (Sandbox Code Playgroud)
版画 It's there!
只有第一个项目在列表中...
if ('a' or 'd') in L:
print 'it\'s there!'
else:
print 'No sorry'
Run Code Online (Sandbox Code Playgroud)
版画 It's there!
列表中没有任何项目......
if ('e' or 'd') in L:
print 'it\'s there!'
else:
print 'No sorry'
Run Code Online (Sandbox Code Playgroud)
版画 No sorry
这是令人困惑的一个只有列表中的第二项......
if ('e' or 'a') in L:
print 'it\'s there!'
else:
print 'No sorry'
Run Code Online (Sandbox Code Playgroud)
版画 No sorry
我不明白为什么这不是一个真实的陈述.这如何概括为具有n个 …
我知道之前已经讨论过这个问题,但我很难找到如何在本地开发和生产服务器之间进行配置的明星解释.
到目前为止我做了什么:我有一个my_app_config.py
文件,其中有一个部分包含机器/场景(测试与生产)部分我可以注释掉.我将使用我的本地机器路径硬编码,测试数据库连接字符串,我的测试电子表格位置等.当需要将代码部署到服务器时,我注释掉"测试"部分并取消注释"生产部分".正如你可能猜到的那样,这是错误的.
我最近采用了Python ConfigParser库来使用.ini
文件.现在,我的代码中有以下几行
import ConfigParser
config = ConfigParser.RawConfigParser()
config.read(os.path.abspath(os.path.join(os.path.dirname( __file__ ), '..', 'settings',
'my_app_config.ini')))
database_connect_string_admin = config.get('Database', 'admin_str')
Run Code Online (Sandbox Code Playgroud)
这个问题很多......
my_app_config.ini
不能改变.所以,我依赖文件内容中的注释.ini
来知道我正在处理哪一个.它们存储在文件夹树中,所以我知道哪个是哪个.我尝试在程序开头设置环境变量,但所有模块的所有导入都会在代码启动时立即执行.我左右都有"未找到"的错误.
我想要的:了解如何将所有配置保存在一个不容易忘记我正在做的事情的地方.我想要一个简单的方法来保持这些配置文件(理想情况下是一个文件或脚本)在版本控制下(安全性是另一个问题,我离题).我希望能够无缝切换上下文(本地测试,本地生产,服务器测试,服务器生产,服务器B测试,服务器B生产)我的应用程序使用
my_app_config.ini
由我的解析器读取uwsgi.ini
由uwsgi应用服务器皇帝读取web_config.py
烧瓶应用使用nginx.conf
符号链接到Web服务器的配置celery
组态更不用说一切的不同路径(理想情况下在魔法配置处理精灵中处理).我想,一旦我想到这一点,我会感到很尴尬,需要很长时间才能掌握.
环境变量是我在这里尝试做的吗?
python ×8
flask ×4
javascript ×2
debugging ×1
flask-admin ×1
ide ×1
ini ×1
jinja2 ×1
mysql ×1
nginx ×1
rxjs ×1
scope ×1
sqlalchemy ×1
typescript ×1
uwsgi ×1
windows ×1