from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
class MainPage(webapp.RequestHandler):
def get(self):
user = users.get_current_user()
if user:
self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write('Hello, ' + user.nickname())
else:
self.redirect(users.create_login_url(self.request.uri))
application = webapp.WSGIApplication(
[('/', MainPage)],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
Run Code Online (Sandbox Code Playgroud)
我不明白这条线的工作原理:
if user:
self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write('Hello, ' + user.nickname())
else:
self.redirect(users.create_login_url(self.request.uri))
Run Code Online (Sandbox Code Playgroud)
我猜这些users.get_current_user()返回一个布尔值?那么,如果是这样的话怎么能得到一个.nickname()方法呢?
感谢您的指导.
我有一个Rails 3应用程序,我使用了很多条件语句来改变页面的设计.为了拥有如此大量的条件,保持逻辑不在视图中的最佳做法是什么?
假设示例:
<% unless @ethos.blank? %>
<%= unless @work.nil? do %>
<%= link_to "Add Work", work_path %>
<% end %>
<%= @ethos.tagline %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
我在其他条件中有更多的条件.在一个视图中管理这个的最佳方法是什么?
我有一个小C程序的问题.它输出一个问题(见下面的代码),我可以将输入放入(y和n),但之后没有其他任何事情发生,即使它是根据输入的输入(y或n)打印某些东西.但是,在我的问题之后没有输出任何内容,程序就会退出.这是代码:
#include <stdio.h>
int main()
{
char string [80];
static char y;
static char n;
printf( "ARE YOU SHAQIRI? [y/n]: " );
scanf( "%s", string );
if ("%s" == "y")
printf("That's impossible. YOU CANNOT BE SHAQIRI YOU IDIOT");
else if ("%s" == "n")
printf("I thought not.");
fflush ( stdin );
return 0;
}
Run Code Online (Sandbox Code Playgroud) 有可能做这样的事情
$( "#till__tablepanel_table_"+tablenumber ).append( "<span>"+if (variable == 1) { writeHere }+"</span>" );
Run Code Online (Sandbox Code Playgroud)
我似乎无法让这个工作.示例:writeHere如果条件成立,我将如何?
我遇到了一个有趣的错误,我很确定它与条件语句的上下文中的包含多态性有关.
该示例的亮点如下:
ClassParent *parentPointer; //Declare pointer to parent
if(condition){
ClassChild1 = mychild; //Declare child1 object
parentPointer = *mychild;//Parent pointer points to child
}
if(!condition){
ClassChild2 = mychild; //Declare child2
parentPointer = *mychild;//Parent pointer points to child2
}
cout << *parentPointer; //What will this point to???
Run Code Online (Sandbox Code Playgroud)
应该清楚,条件语句在最后一行中生成*parentPointer变量.
我的整个函数看起来像这样:(注意崩溃的地方)
void PosApp::addItem(bool isPerishable) {
Item *refitem;
if (isPerishable) {
Perishable myitem;
std::cout << "Enter the following: " << std::endl
<< "Sku: " << std::endl
<< "Name:" << std::endl
<< "Price: " << std::endl …Run Code Online (Sandbox Code Playgroud) 我有两个像这样的阵列:
$scope.values_array = ['string1', 'string2', 'string3', 'string4'];
$scope.skip_array = ['string2', 'string3'];
Run Code Online (Sandbox Code Playgroud)
我尝试使用这样的ng-options:
<select ng-options="value as value for value in values_array && skip_array.indexOf(value) === -1"></select>
Run Code Online (Sandbox Code Playgroud)
这不会产生错误,但下拉列表中不会显示任何内容.如果没有"&& skip_array.indexOf(value)",它会显示values_array中的所有选项.
我使用的是Ember.js版本2.8.2.
我想在link-to条件为真的情况下将内容包装在里面.
首先尝试:
{{#if isAdmin}}
{{#link-to admin}}
contents here
{{/link-to}}
{{else}}
contents here
{{/if}}
Run Code Online (Sandbox Code Playgroud)
问题:代码不干,因为内容重复两次.
我该怎么做?谢谢.
所以,我有两个清单:
x =[170 169 168 167 166 165 183 201 219 237 255 274 293 312 331 350]
y =[201,168]
Run Code Online (Sandbox Code Playgroud)
我想写一个条件if语句,只有当所有内容y都在时才是真的x.我该怎么做呢?
EG - assert(y[0] in x)和assert(y[a] in x)两个给True,但assert(y in x)给人False.同样,assert( any(y) in x )也会引发错误.
有人可以解释我在没有卷曲大括号的情况下编写的嵌套If-Else语句的工作原理.
我想了解为什么以下程序没有给我任何输出.
我检查了所有4种可能性.
(Outer-If,Inner-If)::( True,True),(True,False),(False,True),(False,False).
我在CodeBlocks上编辑,在Windows上使用gcc编译器.
int main()
{
int n=0,m=0;
if ( n > 0 )
if ( m > 0 )
printf("Inner-If Condition satisfied.");
else
printf("Inner-If condition not satisfied. ");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
谢谢.
我正在尝试在Delphi 7中进行血压类别检查,而我刚认识Delphi已有几个星期了。问题是,每当我输入大于120的数字时,标签标题始终显示正常。这是我的代码:
procedure TForm1.Button1Click(Sender: TObject);
var a,b:real;
begin
a:=strtofloat(edit1.Text);
if (a<120) then label1.caption:='optimal'
else if (a>120) then label1.caption:='normal'
else if (a<130) then label1.caption:='normal'
else if (a>130) then label1.caption:='normal high'
else if (a<140) then label1.caption:='normal high'
else if (a>140) then label1.caption:='grade 1 hypertension'
else if (a<160) then label1.caption:='grade 1 hypertension'
else if (a>160) then label1.caption:='grade 2 hypertension'
else if (a<180) then label1.caption:='grade 2 hypertension'
else if (a>181) then label1.caption:='grade 3 hypertension'
end;
end.
Run Code Online (Sandbox Code Playgroud)
可能是一些常见的错误,但我仍然无法自己弄清楚,任何帮助都会有很大帮助,谢谢。
conditional ×10
if-statement ×3
c ×2
python ×2
angularjs ×1
c++ ×1
delphi ×1
delphi-7 ×1
ember.js ×1
filter ×1
inclusion ×1
javascript ×1
jquery ×1
link-to ×1
oop ×1
polymorphism ×1
stdin ×1
string ×1