有没有人知道一个很好的平台无关的例子或库通过Python进行Facebook身份验证和Graph API访问?
官方Facebook Python SDK与Google App Engine绑定,Pyfacebook与Django密切相关.
我只是希望能够在终端中乱搞并完成对用户进行身份验证的过程,然后从Facebook API执行简单请求.
谢谢.
现在我只是检查链接的响应,如下所示:
self.client = Client()
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
Run Code Online (Sandbox Code Playgroud)
是否有一种Django-ic方式来测试链接,看看文件下载事件是否真的发生了?似乎无法在这个主题上找到太多资源.
我看到这个问题从Django的项目和建议,在这里,但仍不能得到这个工作.我的Django Admin页面根本没有显示CSS.

这是我目前的配置.
settings.py
ADMIN_MEDIA_PREFIX = '/media/admin/'
Run Code Online (Sandbox Code Playgroud)
httpd.conf文件
<VirtualHost *:80>
DocumentRoot /home/django/sgel
ServerName ec2-***-**-***-***.ap-**********-1.compute.amazonaws.com
ErrorLog /home/django/sgel/logs/apache_error.log
CustomLog /home/django/sgel/logs/apache_access.log combined
WSGIScriptAlias / /home/django/sgel/apache/django.wsgi
<Directory /home/django/sgel/media>
Order deny,allow
Allow from all
</Directory>
<Directory /home/django/sgel/apache>
Order deny,allow
Allow from all
</Directory>
LogLevel warn
Alias /media/ /home/django/sgel/media/
</VirtualHost>
<VirtualHost *:80>
ServerName sgel.com
Redirect permanent / http://www.sgel.com/
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
另外,我还运行以下内容来创建(我认为)符号链接
ln -s /home/djangotest/sgel/media/admin/ /usr/lib/python2.6/site-packages/django/contrib/admin/media/
UPDATE
在我的httpd.conf文件中,
User django
Group django
Run Code Online (Sandbox Code Playgroud)
当我在我的/media目录中运行ls -l时
drwxr-xr-x 2 root root 4096 Apr 4 11:03 …Run Code Online (Sandbox Code Playgroud) 刚刚在django文档中遇到过这个问题
调用none()将创建一个永远不会返回任何对象的查询集,并且在访问结果时不会执行任何查询.qs.none()queryset是EmptyQuerySet的一个实例.
我构建了很多CRUD应用程序(惊喜),我想不出我需要使用的情况none().
为什么要返回EmptyQuerySet?
我怎么转这个:
data = ((1, '2011-01-01'), (2, '2011-01-02'), (1, '2011-01-15'), (3, '2011-02-01'))
Run Code Online (Sandbox Code Playgroud)
进入这个:
{
"item": [
"1",
"2",
"1",
"3",
],
"settings": {
"axisx": [
"2011-01-01",
"2011-01-02",
"2011-01-15",
"2011-02-01"
],
"axisy": [
"0",
"100"
],
"colour": "ff9900"
}
}
Run Code Online (Sandbox Code Playgroud)
或者更确切地说,是否有任何有用的资源我可以阅读,以便我能够生成该JSON输出?所以我知道我需要将我的数据"转换"为正确的数据结构.之后就这么简单json.dumps(data)
谢谢
15 class Profile(models.Model):
16 """
17 User profile model
18 """
19 user = models.ForeignKey(User, unique=True)
20 country = models.CharField('Country', blank=True, null=True, default='',\
21 max_length=50, choices=country_list())
22 is_active = models.BooleanField("Email Activated")
Run Code Online (Sandbox Code Playgroud)
我有一个像上面的模型country设置为blank=True, null=True.
但是,在提交给最终用户的表格中,我要求完成国家/地区字段.
因此,我在模型表单中重新定义了这样的字段,以"强制"它成为必需:
77 class ProfileEditPersonalForm(forms.ModelForm):
78
79 class Meta:
80 model = Profile
81 fields = ('email',
82 'sec_email',
83 'image',
84 'first_name',
85 'middle_name',
86 'last_name',
87 'country',
88 'number',
89 'fax',)
90
98 country = forms.ChoiceField(label='Country', choices = country_list())
Run Code Online (Sandbox Code Playgroud)
所以国家领域只是一个例子(有很多).有更好的干燥方式吗?
根据文件:
另一方面,TestCase不会在测试开始时截断表并重新加载初始数据.相反,它将测试代码包含在数据库事务中,该事务在测试结束时回滚.它还可以防止被测代码对数据库发出任何提交或回滚操作,以确保测试结束时的回滚将数据库恢复到其初始状态.为了保证所有TestCase代码都以干净的数据库启动,Django测试运行器首先运行所有TestCase测试,然后再进行任何其他测试(例如doctests),这些测试可能会改变数据库而不将其恢复到原始状态.
所以,如果我有一个看起来像这样的测试:
class GeneralUserCreateTest(TestCase):
def setUp(self):
create_roletypes()
create_permissiontypes()
self.client = Client()
self.event = create_event()
def test_create(self):
create_url = reverse('event_user_signup', args=[self.event.slug])
post_data = {
'signup-account-email': 'foo@bar.com',
'signup-account-password': 'foobar',
'signup-account-password2': 'foobar',
'signup-account-first_name': 'Foo',
'signup-account-last_name': 'Bar',
}
response = self.client.post(create_url, data=post_data)
self.assertEqual(response.status_code, 302)
# check creation of user object
self.assertEqual(User.objects.filter(email=post_data['signup-account-email']).count(), 1)
user = User.objects.get(username=post_data['signup-account-email'])
# user and profile objects created
self.assertEqual(User.objects.all().count(), 1)
self.assertEqual(Profile.objects.all().count(), 1)
# get the first user and profile object to test against submitted field
user = User.objects.all()[0]
profile = …Run Code Online (Sandbox Code Playgroud) 只是想知道你们如何管理缓存失效.鉴于缓存中可能存在可能由不同算法或规则触发的对象(数百和数千).你如何跟踪这一切?
无论如何,您是否可以从数据库中的表中引用关系并以某种方式强制执行它?
请耐心等待,因为我以前从未做过任何缓存.
我是Python和Django的初学者.
在开始一个新项目时,在深入研究代码之前,您先做了什么?
例如,可以采取以下步骤:
所以我的问题是,通过Django应用程序所需的步骤是什么样的好工作流程?这也可以作为事情的清单.在Django的权威指南中,作者谈到了自上而下或自下而上的问题.有人可以进一步扩展这个并且可能分享他们的过程吗?
谢谢.
使用pytz,我能够获得如下所示的时区列表:
>>> from pytz import country_timezones
>>> print(' '.join(country_timezones('ch')))
Europe/Zurich
>>> print(' '.join(country_timezones('CH')))
Europe/Zurich
Run Code Online (Sandbox Code Playgroud)
鉴于我从用户那里获得了Country和City字段,我该如何确定城市的时区?
django ×7
python ×6
caching ×1
css ×1
django-admin ×1
django-forms ×1
facebook ×1
json ×1
pyfacebook ×1
unit-testing ×1