小编Hoa*_*ham的帖子

Django模板,如何选择预定义值的下拉框?

我正在尝试创建一个下拉列表框,其中所选值等于从模板值传递的值,但没有成功.任何人都可以看看,告诉我我做错了什么.

     <select name="movie">
       {% for movie in movies %}
    {% ifequal movie.id selected_movie.id %}
     <option value="{{movie.key}}" selected="true">Movie {{movie.id}}: {{movie.name}}</option>
     {% endifequal %}
     {% ifnotequal movie.id selected_movie.id %}
     <option value="{{movie.key}}">Movie {{movie.id}}: {{movie.name}}</option>
     {% endifnotequal %}
       {% endfor %}
     </select>
Run Code Online (Sandbox Code Playgroud)

在此示例中,电影和selected_movie从模板值传递.请指教!

python django django-templates

6
推荐指数
1
解决办法
2万
查看次数

如何在Google App Engine中检查UserProperty的空值

在Google App Engine数据存储建模中,我想问一下如何使用类UserProperty检查属性的空值?例如:我有这个代码:

class Entry(db.Model):
  title = db.StringProperty()
  description = db.StringProperty()
  author = db.UserProperty()
  editor = db.UserProperty()
  creationdate = db.DateTimeProperty()
Run Code Online (Sandbox Code Playgroud)

当我想检查那些编辑器不为null的条目时,我不能使用这种GqlQuery

query = db.GqlQuery("SELECT * FROM Entry " +
                    "WHERE editor IS NOT NULL" +
                                    "ORDER BY creationdate DESC")
    entries = query.fetch(5)
Run Code Online (Sandbox Code Playgroud)

我想知道是否有任何方法用UserProperty检查变量的存在?谢谢!

python google-app-engine google-cloud-datastore

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

我应该在开发服务器上为Google App Engine BulkLoader添加哪些凭据?

我想问一下,使用Google App Engine BulkLoader类导入数据需要使用哪种凭据

appcfg.py upload_data --config_file=models.py --filename=listcountries.csv --kind=CMSCountry --url=http://localhost:8178/remote_api vit/
Run Code Online (Sandbox Code Playgroud)

然后它要求我提供证书:

请输入localhost的登录凭据

这是一个models.py内容的提取,我使用这个listcountries.csv文件

class CMSCountry(db.Model):
  sortorder = db.StringProperty()
  name = db.StringProperty(required=True)
  formalname = db.StringProperty()
  type = db.StringProperty()
  subtype = db.StringProperty()
  sovereignt = db.StringProperty()
  capital = db.StringProperty()
  currencycode = db.StringProperty()
  currencyname = db.StringProperty()
  telephonecode = db.StringProperty()
  lettercode = db.StringProperty()
  lettercode2 = db.StringProperty()
  number = db.StringProperty()
  countrycode = db.StringProperty()

class CMSCountryLoader(bulkloader.Loader):
  def __init__(self):
    bulkloader.Loader.__init__(self, 'CMSCountry',
                           [('sortorder', str),
                            ('name', str),
                            ('formalname', str),
                            ('type', str),
                            ('subtype', str),
                            ('sovereignt', str),
                            ('capital', str), …
Run Code Online (Sandbox Code Playgroud)

python google-app-engine

5
推荐指数
2
解决办法
7153
查看次数

Python是什么意思"AttributeError:'unicode'对象没有属性'has_key'"

我想问一下它是什么意思"AttributeError:'unicode'对象没有属性'has_key'"这是完整的堆栈跟踪:

Traceback (most recent call last):
  File     "D:\Projects\GoogleAppEngine\google_appengine\google\appengine\ext\webapp\__init__.py", line 509, in __call__
    handler.post(*groups)
  File "D:\Projects\workspace\foo\src\homepage.py", line 71, in post
    country=postedcountry
  File "D:\Projects\GoogleAppEngine\google_appengine\google\appengine\ext\db\__init__.py", line 656, in __init__
    prop.__set__(self, value)
  File "D:\Projects\GoogleAppEngine\google_appengine\google\appengine\ext\db\__init__.py", line 2712, in __set__
    value = self.validate(value)
  File "D:\Projects\GoogleAppEngine\google_appengine\google\appengine\ext\db\__init__.py", line 2742, in validate
    if value is not None and not value.has_key():
AttributeError: 'unicode' object has no attribute 'has_key'
Run Code Online (Sandbox Code Playgroud)

让我来描述一下这种情况:

  • 首先,我创建了models.py,其中包含用于CMSRequest的db.Model,其具有引用CMSCountry类的属性country

    class CMSRequest(db.Model):
      country = db.ReferenceProperty(CMSCountry, required=True)
    
    class CMSCountry(db.Model):
      name = db.StringProperty(required=True)
    
    Run Code Online (Sandbox Code Playgroud)
  • 然后,我创建了一个bulkloader类来将数据导入CMSCountry

  • 在表单中,用户可以从下拉列表框中选择国家/地区,结果将被回发并保存到CMSRequest对象

    def post(self):
      postedcountry = self.request.get('country')
      cmsRequest = …
    Run Code Online (Sandbox Code Playgroud)

python google-app-engine

5
推荐指数
1
解决办法
4万
查看次数

使用Google App Engine和Python进行基于角色的安全性

我想问一下使用Google App Engine,Python处理基于角色的安全性的常用方法是什么?

在app.yaml中,有"登录"部分,但可用值仅为"admin"和"required".

您通常如何处理基于角色的安全性?

  • 使用两个表创建模型:角色和UserRoles
  • 导入Roles表的值
  • 手动将用户添加到UserRoles
  • 检查用户是否在正确的角色组中

任何其他想法或任何其他基于角色的安全方法,请告诉我们!

python google-app-engine role-based

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

Pinax能够部署在gae上吗?

使用Pinax开发的应用程序是否有可能部署在谷歌应用程序引擎中?

据我所知,Pinax基于Django,并集成了大量的应用程序,它甚至适用于构建社交网站.它非常有用但我想知道我是否可以在谷歌应用引擎上部署它.

谢谢,

django google-app-engine pinax

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

反向关系警告 - 询问使用反向关系的实践

我有Order表,其中包含有关特定订单的信息(何时启动,有多少人等等),Order表与Menu Item表有To-Many关系.我将这种关系称为"orderItems".

编译器给我警告,"Order.orderedItems - to-many关系没有反转:这是一个高级设置(没有对象可以在特定关系的多个目的地)"

你通常如何做反向关系?我是否需要在菜单项上创建一个新关系以指回Order,并将反向关系设置为"orderedItems"?(事实上​​,我没有理由在菜单项表中保存该数据)

有人可以向我解释为什么,或者至少指出我为什么需要在菜单项表上创建反向关系的原因.

提前致谢,

iphone core-data

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

Beautiful Soup 4 CSS选择器的工作方式与教程显示的方式不同

我从[Beautiful Soup 4教程页面] [1] 运行示例CSS选择器代码,但结果不同,有些给出正确的结果,有些则没有.在网站上,他们说它应该在Python 2.7和3中以相同的方式工作.我有Python 2.7并安装Beautiful Soup 4.有没有人有同样的问题?

from bs4 import BeautifulSoup
import urllib2

html_doc = """
<html><head><title>The Dormouse's story</title></head>
<body>
<p class="title"><b>The Dormouse's story</b></p>

<p class="story">Once upon a time there were three little sisters; and their names were
<a href="http://example.com/elsie" class="sister" id="link1">Elsie</a>,
<a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and
<a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>;
and they lived at the bottom of a well.</p>

<p class="story">...</p>
"""

soup = BeautifulSoup(html_doc)
Run Code Online (Sandbox Code Playgroud)

我的测试(当然我在教程中使用相同的html文档):

soup.select("#link1 ~ .sister")
[]
Run Code Online (Sandbox Code Playgroud)

他们的测试:

soup.select("#link1 ~ …
Run Code Online (Sandbox Code Playgroud)

html css python beautifulsoup css-selectors

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

用于开发Python和Google App Engine的资源

我想问一下使用Python和Google App Engine开发应用程序的一些来源.

例如,欢迎使用插入/更新/删除数据库表或任何其他有用资源自动生成页面的一些控件.

谢谢!

python google-app-engine user-controls controls

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

如何从Documents文件夹中加载动态保存的图像?

我有问题从iPhone应用程序的Documents文件夹中加载图像到tableView.

在单独的请求中,我在服务器上检查所有可用的图像,并将它们下载到Documents下的"images"文件夹中.我很确定图像是否正确保存.

NSString *filePath = [imagesFolderPath stringByAppendingPathComponent:imageFileName];
    [urlData writeToFile:filePath atomically:NO];
NSLog(@"Saved to file: %@", filePath);

2010-01-22 17:07:27.307 Foo[2102:207] Saved to file: /Users/Hoang/Library/Application Support/iPhone Simulator/User/Applications/6133A161-F9DC-4C92-8AE6-5651022EAA94/Documents/images/86_2.png
Run Code Online (Sandbox Code Playgroud)

[NSBundle mainBundle]不适合加载图像,因为在运行时,应用程序尝试连接到服务器以下载图像,它们不是静态的.

但是从Documents/images文件夹加载图像并不能在TableView上显示图像.

static NSString *CellIdentifier = @"CellCategory";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}

// Set up the cell...
UIImageView *imageView = cell.imageView;

MenuItem *item = (MenuItem *) [arrayMenuItems objectAtIndex:indexPath.row];
cell.textLabel.text = item.descrizione;


NSString *strImagePath = [[imagesFolderPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%d_%d", item.idItem, item.idNode]] stringByAppendingPathExtension:@"png"];  
NSLog(@"strImagePath: %@", …
Run Code Online (Sandbox Code Playgroud)

iphone

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

构建通过Web API与服务器同步数据的iPhone应用程序面临的主要挑战是什么?

我想构建一个利用服务器数据的应用程序,它需要将应用程序中的数据与其他客户端应用程序输入的数据同步.所以,有一些问题:

  • 如何有效地设计数据库模式?它应该在服务器上复制相同的数据库模式还是应该添加更多的字段和实体?
  • 有什么策略可以同步数据,在每个应用程序启动时或在应用程序的某些空闲状态期间,或其他什么...
  • 如何处理用户在应用程序中输入的数据与另一个客户端应用程序输入的数据之间的冲突.

欢迎任何回应.

iphone synchronization database-design application-design

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

使用NSTimer计划计时器使任务运行速度超出预期

我安排了一个具有NSTimer功能的计时器,viewWillAppear如下所示:

minutesTimer = nil;
minutesTimer = [NSTimer scheduledTimerWithTimeInterval:60 target:self selector:@selector(updateScrollViewItems) userInfo:NULL repeats:YES];
Run Code Online (Sandbox Code Playgroud)

通过这个函数调用,我希望它updateScrollViewItems每分钟调用一次选择器,但它没有,它更快地更新项目(大约几秒钟).

这种意外行为的原因是什么?

iphone objective-c nstimer

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