我想下载一个可从此链接访问的图像:https://www.python.org/static/apple-touch-icon-144x144-precomposed.png进入我的本地系统.现在,我知道该curl命令可用于通过终端下载远程文件.所以,我在终端中输入以下内容,以便将图像下载到我的本地系统:
curl https://www.python.org/static/apple-touch-icon-144x144-precomposed.png
Run Code Online (Sandbox Code Playgroud)
但是,这似乎不起作用,所以很明显还有其他方法可以从Internet上下载图像curl.使用此命令下载图像的正确方法是什么?
我正在使用Google App Engine开发一个小应用程序,该应用程序使用Quora RSS提要.有一个表单,根据用户输入的输入,它将输出与输入相关的链接列表.现在,应用程序适用于单个字母查询和大多数双字母单词,如果单词用' - '分隔.但是,对于三个字母的单词和一些双字母单词,我收到以下错误:
UnicodeDecodeError:'ascii'编解码器无法解码位置48中的字节0xe2:序数不在范围内(128)
这是我的Python代码:
import os
import webapp2
import jinja2
from google.appengine.ext import db
import urllib2
import re
template_dir = os.path.join(os.path.dirname(__file__), 'templates')
jinja_env = jinja2.Environment(loader = jinja2.FileSystemLoader(template_dir), autoescape=True)
class Handler(webapp2.RequestHandler):
def write(self, *a, **kw):
self.response.out.write(*a, **kw)
def render_str(self, template, **params):
t = jinja_env.get_template(template)
return t.render(params)
def render(self, template, **kw):
self.write(self.render_str(template, **kw))
class MainPage(Handler):
def get(self):
self.render("formrss.html")
def post(self):
x = self.request.get("rssquery")
url = "http://www.quora.com/" + x + "/rss"
content = urllib2.urlopen(url).read()
allTitles = re.compile('<title>(.*?)</title>')
allLinks = …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 BeautifulSoup 提取链接的标题。我正在使用的代码如下:
url = "http://www.example.com"
source_code = requests.get(url)
plain_text = source_code.text
soup = BeautifulSoup(plain_text, "lxml")
for link in soup.findAll('a', {'class': 'a-link-normal s-access-detail-page a-text-normal'}):
title = link.get('title')
print title
Run Code Online (Sandbox Code Playgroud)
现在,一个示例link元素包含以下内容:
<a class="a-link-normal s-access-detail-page a-text-normal" href="http://www.amazon.in/Introduction-Computation-Programming-Using-Python/dp/8120348664" title="Introduction To Computation And Programming Using Python"><h2 class="a-size-medium a-color-null s-inline s-access-title a-text-normal">Introduction To Computation And Programming Using <strong>Python</strong></h2></a>
Run Code Online (Sandbox Code Playgroud)
但是,运行上述代码后,没有任何显示。如何提取存储在title锚标记的属性中的值link?
python beautifulsoup web-scraping python-2.7 python-requests
我在本地构建了一个Django 1.9项目sqlite3作为我的默认数据库.我有一个名为的应用程序Download,用于定义DownloadedSongs表models.py:
models.py
from __future__ import unicode_literals
from django.db import models
class DownloadedSongs(models.Model):
song_name = models.CharField(max_length = 255)
song_artist = models.CharField(max_length = 255)
def __str__(self):
return self.song_name + ' - ' + self.song_artist
Run Code Online (Sandbox Code Playgroud)
现在,为了将我的本地项目部署到Heroku,我在settings.py文件的底部添加了以下行:
import dj_database_url
DATABASES['default'] = dj_database_url.config()
Run Code Online (Sandbox Code Playgroud)
我的应用程序有一个包含几个文本字段的表单,在提交该表单时,数据会插入到DownloadedSongs表中.现在,当我在Heroku上部署我的项目并尝试提交此表单时,我收到以下错误:
Exception Type: ProgrammingError at /download/
Exception Value: relation "Download_downloadedsongs" does not exist
LINE 1: INSERT INTO "Download_downloadedsongs" ("song_name", "song_a...
Run Code Online (Sandbox Code Playgroud)
这是我的requirements.txt文件的样子:
beautifulsoup4==4.4.1
cssselect==0.9.1
dj-database-url==0.4.1
dj-static==0.0.6
Django==1.9
django-toolbelt==0.0.1 …Run Code Online (Sandbox Code Playgroud) 我当前正在使用python中的'urllib'模块,并尝试使用它来提取网站的源代码:
import urllib
temp = urllib.request.urlopen('https://www.quora.com/#')
Run Code Online (Sandbox Code Playgroud)
但是,我收到以下错误:
回溯(最近一次调用最后一次):文件"",第1行,在temp = urllib.request.urlopen(' https://www.quora.com/# ')中AttributeError:'module'对象没有属性'request'
顺便说一句,我正在使用Python 2.7.5.
我正在开发一个应用程序,其中我创建了一个泛型ListView.现在,在我定义该视图时urls.py,我从文档中读到了我需要使用该as_view()方法,如下所示:
from django.conf.urls import patterns, include, url
from .views import BlogIndex
urlpatterns = patterns(
'',
url(r'^$', BlogIndex.as_view(), name="index"),
)
Run Code Online (Sandbox Code Playgroud)
现在,我真的不明白文档对这个方法的看法.有人能否对这个概念有所了解?
我有一个我在Windows 7中创建的应用程序,它运行得很好.几天前,我迁移到Ubuntu并在Ubuntu中复制了项目文件.现在,当我尝试使用项目运行时python manage.py runserver,我收到以下错误:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 312, in execute
django.setup()
File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 112, in create
mod = import_module(mod_path)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named social.apps.django_app
Run Code Online (Sandbox Code Playgroud)
这里看起来有什么不对?我是Ubuntu的新手,所以任何帮助都会受到赞赏.我在Ubuntu中安装了与在Windows中安装的相同版本的Python和Django.
我的应用程序中有一个模型表单,我希望我的两个模型表单字段是可选的,即用户可以将这两个表单字段留空,并且 Django 表单验证不应引发相同的错误。
我已经设置blank = True并null = True为这两个字段,如下所示:
questions = models.CharField(blank=True, null = True, max_length=1280)
about_yourself = models.CharField(blank=True, null = True, max_length=1280)
Run Code Online (Sandbox Code Playgroud)
表格.py
questions = forms.CharField(help_text="Do you have any questions?", widget=forms.Textarea)
about_yourself = forms.CharField(help_text="Tell us about yourself", widget=forms.Textarea)
Run Code Online (Sandbox Code Playgroud)
但是,如果提交时将这两个字段留空,This field is required则会引发 a。
这里似乎有什么问题?如何在 Django 中设置可选的模型表单字段?
我创建了一个自定义帖子类型,wrestling并使用高级自定义字段创建了相应的自定义字段.现在,我希望用户在前端填写此自定义表单,以便在提交时,数据将在仪表板中的自定义帖子类型中自动更新.为此,我创建了一个自定义页面并为其分配了一个包含所需表单的自定义模板.有迹象表明,用户都应该装满四个HTML表单字段,命名为name,venue,main_event和fee分别.
我使用高级自定义字段创建自定义表单域被命名为promotion_name,venue,main_event_和price分别.现在,为了将前端用户输入的数据填充到仪表板上的自定义帖子类型字段,我尝试使用wp_insert_post()如下函数:
$post_information = array(
'promotion_name' => $_POST['name'],
'venue' => $_POST['venue'],
'main_event_' => $_POST['main_event'],
'price' => $_POST['fee'],
'post_type' => 'wrestling',
);
wp_insert_post( $post_information );
Run Code Online (Sandbox Code Playgroud)
但是,在用户提交表单后,我的自定义帖子类型中会出现一个新条目(no_title),但自定义表单字段仍为空(请参阅下面的图片:)
我确定这是因为我没有wp_insert_post()正确使用更新自定义帖子类型.我真的很感激这里的一些帮助.谢谢.
PS:这就是我定义自定义帖子类型的方式functions.php:
<?php
function wrestling_show_type()
{
register_post_type('wrestling',
array('labels' => array('name' => 'Wrestling Shows', 'singular_name' => 'Wrestling Show'),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'wrestling')));
flush_rewrite_rules();
}
add_action('init', …Run Code Online (Sandbox Code Playgroud) 我正在尝试Asia/Calcutta通过访问/etc/php5/cli/php.ini文件并更改来更改默认的PHP时区
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
;date.timezone =
Run Code Online (Sandbox Code Playgroud)
至
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = "Asia/Calcutta"
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试查看当前时区时phpinfo(),时区遵循Europe/Berlin时区.
我已经尝试停止并重新启动Apache服务器,但似乎没有更改设置.
在这个过程中有什么我想念的吗?
PS:我正在使用目前在XAMPP下的PHP 5.6.8.
python ×7
python-2.7 ×6
django ×4
forms ×2
php ×2
ubuntu ×2
curl ×1
datetime ×1
django-1.7 ×1
heroku ×1
html ×1
jinja2 ×1
linux ×1
terminal ×1
ubuntu-14.04 ×1
unicode ×1
web-scraping ×1
wordpress ×1