小编kur*_*urd的帖子

对象没有属性'save'Django

不知道如何处理这个错误.如何使用post方法从表单中添加SQL数据?

models.py

class Lala(models.Model):
    PRIORITY_CHOICES = ( 
        (0, '1'),
        (1, '2'),
        (2, '3'),
        (3, '4'),
     )
    name = models.CharField(max_length=20)
    date = models.DateField()
    priority = models.CharField(max_length=1, choices=PRIORITY_CHOICES)
Run Code Online (Sandbox Code Playgroud)

Views.py

def add (request):
    if request.method == 'POST': # If the form has been submitted...
        form = AddLala(request.POST) # A form bound to the POST data
        if form.is_valid():
            newform = form.save()
Run Code Online (Sandbox Code Playgroud)

Form.py

class AddLala(forms.Form):
    PRIORITY_CHOICES = ( 
        (0, '1'),
        (1, '2'),
        (2, '3'),
        (3, '4'),
     )
    name = forms.CharField(max_length=100)
    date = forms.DateField()
    priority = …
Run Code Online (Sandbox Code Playgroud)

forms django

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

如何使用美丽的汤和蟒蛇获得图标

我写了一些愚蠢的代码用于学习,但它不适用于任何网站.这是代码:

import urllib2, re
from BeautifulSoup import BeautifulSoup as Soup

class Founder:
    def Find_all_links(self, url):
        page_source = urllib2.urlopen(url)
        a = page_source.read()
        soup = Soup(a)

        a = soup.findAll(href=re.compile(r'/.a\w+'))
        return a
    def Find_shortcut_icon (self, url):
        a = self.Find_all_links(url)
        b = ''
        for i in a:
            strre=re.compile('shortcut icon', re.IGNORECASE)
            m=strre.search(str(i))
            if m:
                b = i["href"]
        return b
    def Save_icon(self, url):
        url = self.Find_shortcut_icon(url)
        print url
        host = re.search(r'[0-9a-zA-Z]{1,20}\.[a-zA-Z]{2,4}', url).group()
        opener = urllib2.build_opener()
        icon = opener.open(url).read()
        file = open(host+'.ico', "wb")
        file.write(icon)
        file.close()
        print '%s …
Run Code Online (Sandbox Code Playgroud)

python favicon beautifulsoup

4
推荐指数
2
解决办法
3936
查看次数

如何在bash中解析json或将curl输出传递给python脚本

我想找到一些方法在json中打印出curl的输出.我为此目的写了一个简短的python脚本,但它不适用于管道我也不想使用子进程并从它们运行curl:

所以python:

#!/usr/bin/python

import simplejson
from pprint import pprint
import sys
print pprint(simplejson.loads(sys.argv[1]))
Run Code Online (Sandbox Code Playgroud)

而json的信息是:

{"response": {"utilization": {"eic": [{"date": "2012.03.06", "usage": []}, {"date": "2012.03.07", "usage": [{"srvCode": "SVC302", "upload": 267547188, "api-calls": {"fileGetInfo": 30, "getUserStorageQuota": 0, "setUserStorageQuota": 0, "fileUploadFlashInit": 31, "getAPISessionUser": 0, "setFileAccessControl": 0, "fileGetPreviewUrl": 0, "fileStartMultipartUpload": 0, "getServiceQuota": 0, "fileGetPreviewUrlsForBunch": 10, "xcodingGetStreamUrl": 0, "getSessionTimeLimit": 0, "fileGetCoversUrlsForBunch": 27, "makePreviews": 0, "setServiceQuota": 0, "getAPISessionTrusted": 3, "getFileAccessControl": 0, "xcodingGetFormats": 0, "getQuotaNotificationEmail": 0, "fileGetDownloadUrl": 0, "xcodingGetStreamInfo": 0, "fileUploadDone": 30, "getLocalServiceUtilization": 9, "getServiceUtilization": 0, "fileDelete": 19, "setSessionTimeLimit": …
Run Code Online (Sandbox Code Playgroud)

python bash json pprint

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

Py.test运行直到通过装饰器

我有一些测试可以上传不同的数据(音乐,视频)并从服务中获取元数据.

所以time.sleep()是一种非常糟糕的方式,因为不同的服务器和情况可能使系统过载.

所以我正在寻找特殊的装饰器或参数来设置.像这样的东西

@fails(10)
def test_get_info(self):
    assert info == 1
Run Code Online (Sandbox Code Playgroud)

在10次尝试之后断言仍然失败 - 引发异常.

谢谢.

python pytest

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

标签 统计

python ×3

bash ×1

beautifulsoup ×1

django ×1

favicon ×1

forms ×1

json ×1

pprint ×1

pytest ×1