这是我在模板中的代码.
{% if 'index.html' in "{{ request.build_absolute_uri }}" %}
'hello'
{% else %}
'bye'
{% endif %}
Run Code Online (Sandbox Code Playgroud)
现在我的网址值是 "http://127.0.0.1:8000/login?next=/index.html"
即使"index.html"
它在字符串中仍然打印再见.
当我在python shell中运行相同的代码时,它可以工作.不确定是什么错误.
我的flask_login模块有问题.
我已经成功安装了flask_login模块.同样从命令提示符,我可以轻松地运行此脚本,没有错误:
Python 2.7 (r27:82525, Jul 4 2010, 07:43:08) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from flask.ext.login import LoginManager
Run Code Online (Sandbox Code Playgroud)
但是当我运行这个脚本时:
from flask import Flask
from flask.ext.login import LoginManager
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World! Welcome"
if __name__ == "__main__":
app.run()
Run Code Online (Sandbox Code Playgroud)
我收到错误:
ImportError: No module named flask.ext.login
Run Code Online (Sandbox Code Playgroud)
我在做什么错.我对这个烧瓶很新.提前致谢.
这是我的Python Django自定义模板标签代码
from django import template
from ipc.declarations.models import MainDeclaration
from django.shortcuts import get_object_or_404
register = template.Library()
def section_settings(declarationId,user):
declaration = get_object_or_404(MainDeclaration, pk=declarationId, user=user)
businessInfo = declaration.GetOrCreateBusinessInfo()
sections = declaration.GetSections()
return sections
register.assignment_tag(section_settings)
Run Code Online (Sandbox Code Playgroud)
现在我收到了一个错误
register.assignment_tag(section_settings)
[Thu Jan 09 06:50:44 2014] [error] [client 127.0.0.1] AttributeError: 'Library' object has no attribute 'assignment_tag'
这适用于我的开发服务器应用程序,但在生产服务器中上载相同的代码时无法正常工作.
请指导我.
base_path = os.path.dirname(os.path.abspath(__file__))
_csvFilename = os.path.join(base_path, "bcForecasting.csv")
_csvFile = open (_csvFilename, 'wb')
_csvFile = csv.writer(_csvFile, quoting=csv.QUOTE_ALL)
_Header = self.makeIntoList (self.root.tss.series () [0].getAllTimes (), self.originalTimesteps + _futurePeriods)
_csvFile.writerow (_Header)
Run Code Online (Sandbox Code Playgroud)
现在我想bcForecasting.csv
在Excel中打开创建的文件.怎么用Python做?
我的数据框读起来像:
df1
user_id username firstname lastname
123 abc abc abc
456 def def def
789 ghi ghi ghi
Run Code Online (Sandbox Code Playgroud)
df2
user_id username firstname lastname
111 xyz xyz xyz
456 def def def
234 mnp mnp mnp
Run Code Online (Sandbox Code Playgroud)
现在我想要一个像
user_id username firstname lastname
123 abc abc abc
456 def def def
789 ghi ghi ghi
111 xyz xyz xyz
234 mnp mnp mnp
Run Code Online (Sandbox Code Playgroud)
由于 user_id456
在两个数据帧中都是通用的。我已经在 user_id 上尝试过 groupby groupby(['user_id'])
。但看起来 groupby 需要跟随一些aggregation
我不想要的东西。
我在django面临一个问题.以下是我的代码片段:
{% if pageName != 'My page Name' %}
.....{{ then this }}
Run Code Online (Sandbox Code Playgroud)
现在这适用于英语,现在当我用另一种语言翻译我的应用程序时,pageName
也根据该语言改变了.因此上述逻辑不起作用,因为它是硬编码的英语
所以我必须尝试用翻译版本来实现逻辑'My page Name'
.但我不能直接使用它if
:
{% if pageName != trans 'My page Name' %}
Run Code Online (Sandbox Code Playgroud)
所以我想把翻译版本存储在另一个变量中,然后用这个变量检查:
{%blocktrans%} "My page Name" {{myvar}} {%endblocktrans%}
{% if pageName != myvar %}
Run Code Online (Sandbox Code Playgroud)
但是,这也不是工作myvar
需要的价值"My page Name"
,不是它的翻译版本.
任何线索如何解决它.提前致谢.
第一个数据帧df1:
seq id a1 a2
12 209981 None None
12 209982 Funds None
13 209983 Free_Income None
13 209984 Free_Income None
14 209985 Free_Income Hybrid
Run Code Online (Sandbox Code Playgroud)
和我的第二个数据帧df2:
seq a1 p1 p2
12 Funds 5.71 1.09
12 Free_Income 2.18 3.17
12 Hybrid 2.88 3.70
13 Free_Income 2.53 2.64
13 Funds 7.08 3.09
13 Hybrid 7.28 3.99
14 Free_Income 4.53 2.25
14 Hybrid 1.89 2.45
14 Funds 1.13 2.35
Run Code Online (Sandbox Code Playgroud)
现在我想要以下格式的输出
seq id a1 a2 p1 p2 p3 p4
12 209981 None None None …
Run Code Online (Sandbox Code Playgroud) 如何从auth_user
django中的表中获取用户ID .假设用户名可以使用.
尝试使用命令启动服务器时遇到问题
python manage.py runserver 0.0.0.0:8000
Run Code Online (Sandbox Code Playgroud)
它显示
C:\abc>python manage.py runserver 0.0.0.0:8000
Validating models...
0 errors found
Django version 1.4.9, using settings 'abc.settings'
Development server is running at http://0.0.0.0:8000/
Quit the server with CTRL-BREAK.
Run Code Online (Sandbox Code Playgroud)
但无法通过浏览器访问 http://127.0.0.1:8000
它显示:
Unable to connect
Firefox can't establish a connection to the server at 127.0.0.1:8000.
The site could be temporarily unavailable or too busy. Try again in a few moments.
If you are unable to load any pages, check your computer's network connection.
If your computer or …
Run Code Online (Sandbox Code Playgroud) 我有2个词典列表.
list1 = [{'user_id':23, 'user_name':'John', 'age':30},
{'user_id':24, 'user_name':'Shaun', 'age':31},
{'user_id':25, 'user_name':'Johny', 'age':32}]
list2 =[{'user_id':23},
{'user_id':25}]
Run Code Online (Sandbox Code Playgroud)
现在我想要输出
list3 = [{'user_id':23, 'user_name':'John', 'age':30},
{'user_id':25, 'user_name':'Johny','age':32}]
Run Code Online (Sandbox Code Playgroud)
我想要最有效的方式,因为我list1
可能包含数百万行.
python ×9
django ×5
pandas ×2
automation ×1
excel ×1
flask ×1
flask-login ×1
python-2.7 ×1
scripting ×1
windows ×1