小编Jay*_*Jay的帖子

13
推荐指数
2
解决办法
5552
查看次数

Django 模板:如何显示其键中有一个点的字典?d['key.name']

我有一本这样的字典:

dict_name['keyname.with.manydots']
Run Code Online (Sandbox Code Playgroud)

问题:我不能做

{{ dict_name.keyname.with.manydots }} 
Run Code Online (Sandbox Code Playgroud)

我知道用 Django 的模板是不可能做到这一点的……但是你找到的最好的解决方法是什么?谢谢!

tags django templates filter

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

pycurl安装:(已经有min.libcurl版本

我在Intel Mac OS X 10.5上运行python 2.6

我正在尝试安装pycurl 7.16.2.1(这里推荐http://curl.haxx.se/mail/curlpython-2009-03/0009.html),但出于某种原因,安装会看到我的libcurl 7.16.3 ,但它仍然坚持我安装7.16.2或更高(7.16.3不满足?)

这是错误输出:

Running pycurl-7.16.2.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-3emZIB/pycurl-7.16.2.1/egg-dist-tmp-K10rbP
Using curl-config (libcurl 7.16.3)
src/pycurl.c:54:4:src/pycurl.c:54:4: error: #error "Need libcurl version 7.16.2 or greater to compile pycurl."
 error: #error "Need libcurl version 7.16.2 or greater to compile pycurl."
Run Code Online (Sandbox Code Playgroud)

确定curl-config --version会产生libcurl 7.16.3

有什么建议?我应该升级libcurl,还是坚持使用出厂默认的lib?

==在响应==后添加更多详细信息

我有的AFAIK python是出厂默认设置(我没有从python.org获取)

Python 2.6.2 (r262:71600, Apr 16 2009, 09:17:39) 
[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
Run Code Online (Sandbox Code Playgroud)

这是我的卷曲版本.看起来很误导,因为我使用的是英特尔Macbook,而不是PPC.

curl 7.16.3 (powerpc-apple-darwin9.0) libcurl/7.16.3 OpenSSL/0.9.7l zlib/1.2.3
Protocols: tftp ftp telnet …
Run Code Online (Sandbox Code Playgroud)

python macos libcurl pycurl

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

Django 自定义管理员 admin.site.register + admin.site.unregister 冲突 AlreadyRegistered + NotRegistered on 1st HTTP GET (Apache + mod WSGI)

在第一次 HTTP GET 期间(在重新加载守护进程模式下的 WSGI 之后),admin.site.unregister 抛出一个 NotRegistered 异常,但 admin.site.register 抛出一个 AlreadyRegistered 异常(catch-22?)但是,在随后的 HTTP GET 中,一切都加载得很好,没有错误。

设置:

  • 姜戈 1.3
  • 阿帕奇 2.2
  • CentOS

设置.py:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    #'django.contrib.sites', #(this didn't seem to make a difference)
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    'django.contrib.admindocs',
    'base',
    'sample',
    'reports',
    'south',
)
Run Code Online (Sandbox Code Playgroud)

模型.py:

from django.db import models
from django.contrib import admin
from django.contrib.auth.models import User
from django.contrib.auth.admin import …
Run Code Online (Sandbox Code Playgroud)

python apache django mod-wsgi wsgi

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

Django AttributeError:对象没有属性“assertContains”

我正在尝试官方文档中的 Django 测试装置,但我的测试类找不到assertContains。

from django.utils import unittest
from django.test import Client

class SimpleTest(unittest.TestCase):
    def setUp(self):
        self.client = Client()

    def test_details(self):
        response = self.client.post('/register',
                                    {'username': '123',
                                     'password': '123',
                                    follow=True)
        self.assertEqual(response.status_code, 200)

        self.assertContains(response, "Logout")
        self.assertNotContains(response, "Login")
Run Code Online (Sandbox Code Playgroud)

testing django unit-testing testcase

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