小编Hou*_*man的帖子

Django-countries:如何翻译?

我今天安装了django国家.它的工作非常整洁.

不幸的是,文档有点薄,它说:

国家/地区由两部分元组组成的元组,每个元组由一个国家/地区代码和相应的标题清晰(可翻译)的国家/地区名称组成.

我是否只是沿着django国际化的常规路径走下去,它会自动选择并允许我在我的PO文件中定义国家/地区?或者还需要额外的魔法吗?

我实现它的方式是这样的:

from django_countries.countries import COUNTRIES
from django_countries.fields import CountryField

country             = CountryField(_(u'Country'), choices=COUNTRIES,  blank=True)
Run Code Online (Sandbox Code Playgroud)

COUNTRIES直接来自扩展名,因此我没有权限放置_(u)每个国家/地区名称.(from django.utils.translation import ugettext_lazy as _)

django django-countries

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

rauth/flask:如何通过Twitter登录?

rauth中提供的示例是使用PIN而不是回调.我不明白这应该通过网络回调如何工作.

1)小问题:

根据twitter,如果oauth_callback传入了URL,则应该使用它来代替https://dev.twitter.com设置中的任何条目.然而,这似乎不是真的,如果我没有设置它,http://127.0.0.1:8080/twitter/authorized它将永远不会成功授权后到达该Url.

app.add_url_rule('/twitter/login', view_func=views.twitter_login)  
app.add_url_rule('/twitter/authorized', 'twitter_authorized', view_func=views.twitter_authorized)

def twitter_login():
    request_token, request_token_secret = twitter.get_request_token()
    redirect_uri = url_for('twitter_authorized', _external=True)
    params = {'oauth_callback': redirect_uri, 'request_token':request_token}
    return redirect(twitter.get_authorize_url(**params))
Run Code Online (Sandbox Code Playgroud)

2)主要问题在于:

我可以看到request.args有['oauth_token']['oauth_verifier'].但我不明白如何使用它们获取Twitter会话以获取用户详细信息,如图片和显示名称:

def twitter_authorized():
    tw_session = twitter.get_auth_session(request_token ??? , request_token_secret ???)
    resp = tw_session.get("account/verify_credentials.json", params={'format':'json'})    
    me = resp.json()
    user = User.get_or_create(...)

    if user:  
        login_user(user)            
    return redirect(url_for('index'))
Run Code Online (Sandbox Code Playgroud)

如果有人能够对此有所了解,我将非常感激.

flask twitter-oauth rauth

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

linux开发环境中的.net MVC等效于什么?

我多年来一直是.net开发人员,最近对在Linux而不是Microsoft Windows上开发Web应用程序感兴趣。

我特别喜欢MVC的地方是,您可以很容易地获得一个正在运行的项目(+生产率),还有一个Code-First方法(实体框架4.1),该方法允许在开发过程中即时构建数据库。

所以我想知道Linux上是否有一个受支持的框架,您可以向我推荐?用什么语言呢?

非常感谢,

linux asp.net-mvc

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

Django 中的国际化没有被激活

我已经按照文档如何做 i18n 但这些词仍然以英文显示。

设置.py:

USE_I18N = True
LANGUAGES = (
  ('en', 'English'),
  ('de', 'German'),
)
LANGUAGE_CODE = 'de'
Run Code Online (Sandbox Code Playgroud)

意见:

from django.utils.translation import ugettext as _
...
messages.set_level(request, messages.SUCCESS)
messages.success(request, _(u'An invitation was sent to %s.') % invitation.email)
Run Code Online (Sandbox Code Playgroud)

我正在 Ubuntu 上开发并安装了 gettext。在命令行中,我输入这些:

django-admin.py makemessages -l de
Run Code Online (Sandbox Code Playgroud)

我得到一个 .po 文件并相应地编辑它:

# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, …
Run Code Online (Sandbox Code Playgroud)

django

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

如何检查时间值?

我想知道给定的时间是在上午还是下午.我不确定这是否是在python中创建Time对象并进行比较的正确方法.或者,还有更好的方法?

def part_of_day_statistics(x):
    if x > time.strptime('6:00 am') and x < time.strptime('11:59 am'):
        return 'Morning' 
    if x > time.strptime('12:00 pm') and x < time.strptime('5:59 pm'):
        return 'Afternoon' 
Run Code Online (Sandbox Code Playgroud)

python django time

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

当行已经用单引号包装时,如何在trans中转义单引号?

{% trans 'Enter your friend's name and email below, and click "send invite" to invite your friend.' %}
Run Code Online (Sandbox Code Playgroud)

该行已经用单引号括起来,并且该行中也使用了双引号.那么我怎么能逃到friend's这里?

django

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

无法识别的选择器发送到实例

我在选择通知方法时遇到问题.

在init中我已经定义了这个:

NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(stopSyncIndicator:) name:IOS_STOP_SYNC_INDICATOR object:nil];
Run Code Online (Sandbox Code Playgroud)

不过,在头文件和相同的实现中都定义了该方法:

-(void)stopSyncIndicator
{
    [indicator stopAnimating];
}
Run Code Online (Sandbox Code Playgroud)

但是,当其他班级发布此通知时:

NSNotification *note = [NSNotification notificationWithName:IOS_STOP_SYNC_INDICATOR object:nil];
[[NSNotificationCenter defaultCenter] postNotification:note];
Run Code Online (Sandbox Code Playgroud)

地狱破裂了:

[FTRecordViewController stopSyncIndicator:]: unrecognized selector sent to instance 0x8d3bc00
2013-11-18 13:47:06.994 [1835:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FTRecordViewController stopSyncIndicator:]: unrecognized selector sent to instance 0x8d3bc00'
*** First throw call stack:
(
    0   CoreFoundation                      0x01bf75e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x018f88b6 objc_exception_throw + 44
    2   CoreFoundation                      0x01c94903 -[NSObject(NSObject) doesNotRecognizeSelector:] …
Run Code Online (Sandbox Code Playgroud)

nsnotificationcenter ios ios7

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

如何将mock.patch移动到setUp?

我有以下两个单元测试:

    @mock.patch('news.resources.generator.Generator.get_header')
    @mock.patch('news.scraper.bbc_spider.BBCSpider.save_scraped_rss_into_news_model')
    @mock.patch('news.scraper.bbc_spider.BBCSpider.get_news_urls')
    @mock.patch('requests.get')
    def test_get_header_is_called(self, req_get, spi_news, spi_save_rss, get_head):
        spi_news.return_value = {'x': 1}
        gen = Generator()
        gen.get()
        get_head.assert_called_with()

    @mock.patch('news.resources.generator.Generator.get_header')
    @mock.patch('news.scraper.bbc_spider.BBCSpider.save_scraped_rss_into_news_model')
    @mock.patch('news.scraper.bbc_spider.BBCSpider.get_news_urls')
    @mock.patch('requests.get')
    def test_task_url_is_save_scraped_rss_into_news_model(self, req_get, spi_news, spi_save_rss, get_head):
        spi_news.return_value = {'x': 1}
        gen = Generator()
        gen.get()
        tasks = self.taskqueue_stub.GetTasks("newstasks")
        self.assertEqual(tasks[0]['url'], '/v1/worker/save-scraped-rss-into-news-model')
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,有很多代码重复.有没有办法将mock.patch移动到setUp()?

Class TestGenerator(TestBase):
    def setUp(self):
        super(TestGenerator, self).setUp()
        mock.patch() ???

    def test_get_header_is_called(self, req_get, spi_news, spi_save_rss, get_head):
            spi_news.return_value = {'x': 1}
            gen = Generator()
            gen.get()
            get_head.assert_called_with()

    def test_task_url_is_save_scraped_rss_into_news_model(self, req_get, spi_news, spi_save_rss, get_head):
            spi_news.return_value = {'x': 1}
            gen = Generator() …
Run Code Online (Sandbox Code Playgroud)

python unit-testing mocking

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

在 ubuntu 上设置 PYTHONPATH 失败并显示“无效标识符”

我试图在没有运气的情况下在 Ubuntu 服务器上设置 Pythonpath。

export PYTHONPATH=$PYTHONPATH:/home/ubuntu/canonicaliser_api
Run Code Online (Sandbox Code Playgroud)

这执行时没有任何错误,但是当我想仔细检查变量时。

export $PYTHONPATH
Run Code Online (Sandbox Code Playgroud)

我明白了:

-bash: export: `:/home/ubuntu/canonicaliser_api': not a valid identifier
Run Code Online (Sandbox Code Playgroud)

我在谷歌上找不到任何东西。这是什么原因造成的?

bash ubuntu

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

Silverlight:客户端/服务器层是否必要?

我来自WPF/Windows应用程序背景,正在学习Silverlight/Web.让我困惑的第一件事就是层级.在Windows应用程序中,您可以在客户端之间进行明确分离 - 需要在每台用户计算机上进行部署 - 然后与Windows服务/ Web服务进行通信.然后后者又与数据库通信以检索所请求的数据.

在Silverlight中,一切似乎都更容易.没有客户端要部署,用户只需打开浏览器并输入URL地址即可完成.在我的silverlight应用程序所在的托管点,我可以直接在本地与服务程序集通话,而无需将其单独放在不同的Web服务上,对吗?或者我在这里错过了一点?

非常感谢您的建议,Kave

.net silverlight

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