我在Django中有模型设置如下.
class Pupil(models.Model):
forename = models.CharField(max_length=30)
surname = models.CharField(max_length=30)
dateofbirth = models.DateField()
year = models.IntegerField()
class_group = models.CharField(max_length=30)
email = models.EmailField(blank=True)
assignments = models.ManyToManyField('Assignment', verbose_name='related assignments')
def __unicode__(self):
return u'%s %s' % (self.forename, self.surname)
class Subject(models.Model):
name = models.CharField(max_length=30)
level = models.CharField(max_length=30)
teachers = models.ManyToManyField('Teacher', verbose_name='related teachers')
def __unicode__(self):
return self.name
class Teacher(models.Model):
forename = models.CharField(max_length=30)
surname = models.CharField(max_length=30)
email = models.EmailField(blank=True)
def __unicode__(self):
return u'%s %s' % (self.forename, self.surname)
class Assignment(models.Model):
assignment_name = models.CharField(max_length=30)
date_assigned = models.DateField()
date_submitted = …Run Code Online (Sandbox Code Playgroud) 在经历了sqlite3的这个冲泡问题之后,我做到了
brew rm sqlite python python3
Run Code Online (Sandbox Code Playgroud)
然后
brew install python python3
Run Code Online (Sandbox Code Playgroud)
这安装python2.7.5作为默认解释器和brew安装pip以及python,我以为我能够
pip install virtualenv
Run Code Online (Sandbox Code Playgroud)
为新的python2.7.5安装virtualenv.但是,我得到了
-bash: /usr/local/share/python/pip: /usr/local/Cellar/python/2.7.3/bin/python: bad interpreter: No such file or directory
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?我应该在之间创建一个符号链接
/usr/local/share/python/pip --> /usr/local/Cellar/python/2.7.5/bin/pip-2.7
Run Code Online (Sandbox Code Playgroud) 我无法启动我的事件处理程序.我正在将JSON调用到页面中,如下所示.然后,我希望能够单击我创建的一个按钮,该按钮将执行"hello there"警报.它适用于页面上的每个其他元素,但不适用于<button>.
有人可以帮忙吗?
test.js
$(document).ready(function() {
$.getJSON('/api/v1/recipe/?format=json', function(data) {
$.each(data.objects, function(i, recipe) {
$('table#recipes').append('<tr><td>' + recipe.title + '</td><td>' + recipe.ingredients + '</td><td>' + recipe.method + '</td><td><button class="btn" type="button" id="rmv">remove</button></td></tr>');
});
});
$('rmv').on('click', function() {
alert('hello there!');
});
});
Run Code Online (Sandbox Code Playgroud)
recipe.html
{% extends 'base.html' %}
{% block content %}
<div class="container-fluid">
<div class="row-fluid">
<div class="span6">
<form action='' method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="go baby!">
</form>
</div>
<div class="span6">
<table class="table table-striped table-bordered" id="recipes">
<tr>
<th>Title</th>
<th>Ingredients</th>
<th>Method</th> …Run Code Online (Sandbox Code Playgroud) 我有一个scrapy蜘蛛爬行网站,通过页面上的JavaScript重新加载内容.为了进入下一页抓取,我一直在使用Selenium点击网站顶部的月份链接.
问题在于,即使我的代码按预期移动每个链接,蜘蛛也会抓住月份的第一个月(Sept)数据并返回此重复数据.
我怎么能绕过这个?
from selenium import webdriver
class GigsInScotlandMain(InitSpider):
name = 'gigsinscotlandmain'
allowed_domains = ["gigsinscotland.com"]
start_urls = ["http://www.gigsinscotland.com"]
def __init__(self):
InitSpider.__init__(self)
self.br = webdriver.Firefox()
def parse(self, response):
hxs = HtmlXPathSelector(response)
self.br.get(response.url)
time.sleep(2.5)
# Get the string for each month on the page.
months = hxs.select("//ul[@id='gigsMonths']/li/a/text()").extract()
for month in months:
link = self.br.find_element_by_link_text(month)
link.click()
time.sleep(5)
# Get all the divs containing info to be scraped.
listitems = hxs.select("//div[@class='listItem']")
for listitem in listitems:
item = GigsInScotlandMainItem()
item['artist'] = listitem.select("div[contains(@class, 'artistBlock')]/div[@class='artistdiv']/span[@class='artistname']/a/text()").extract()
#
# …Run Code Online (Sandbox Code Playgroud) $ echo $PATH
/usr/local/share/python:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
Run Code Online (Sandbox Code Playgroud)
所以/ usr/local/bin就在我的路上.
当我做`哪个python3'
/usr/local/bin/python3
Run Code Online (Sandbox Code Playgroud)
当我然后尝试创建virtualenv
mkvirtualenv py3000 --python=python3
The executable /Users/misdirectedpuffin/python3 (from --python=/Users/misdirectedpuffin/python3) does not exist
Run Code Online (Sandbox Code Playgroud)
Virtualenv在使用默认python时工作 mkvirtualenv testenv' and when doing 'mkvirtualenv py3000 --python=/usr/local/bin/python3
它似乎在寻找$ HOME for python3.我怎么能纠正这个?
**编辑**
我还可以设置export python3=/usr/local/bin/python3在bash_profile,然后调用$python3用--python=$python3,但我真正想要的是--python=python3不美元符号.