我正在运行以下命令,以便在该文件" pip install -r requirements.txt --download-cache=~/tmp/pip-cache
"中安装软件包
.
requirement.txt包含像pacakages
# Data formats
# ------------
PIL==1.1.7 #
html5lib==0.90
httplib2==0.7.4
lxml==2.3.1
# Documentation
# -------------
Sphinx==1.1
docutils==0.8.1
# Testing
# -------
behave==1.1.0
dingus==0.3.2
django-testscenarios==0.7.2
mechanize==0.2.5
mock==0.7.2
testscenarios==0.2
testtools==0.9.14
wsgi_intercept==0.5.1
Run Code Online (Sandbox Code Playgroud)
当我想要安装"lxml"软件包时,我得到了以下的错误
Requirement already satisfied (use --upgrade to upgrade): django-testproject>=0.1.1 in /usr/lib/python2.7/site-packages/django_testproject-0.1.1-py2.7.egg (from django-testscenarios==0.7.2->-r requirements.txt (line 33))
Installing collected packages: lxml, Sphinx, docutils, behave, dingus, mock, testscenarios, testtools, South
Running setup.py install for lxml
Building lxml version 2.3.1.
Building without Cython.
ERROR: /bin/sh: xslt-config: …
Run Code Online (Sandbox Code Playgroud) views.py
if 'send_email' in request.POST:
subject, from_email, to = 'Parent Incident Notification',user.email, person.parent_email
html_content = render_to_string('incident/print.html',{'person':person,
'report':report,
})
text_content = strip_tags(html_content)
msg = EmailMultiAlternatives(subject, text_content, settings.DEFAULT_FROM_EMAIL, [to])
msg.attach_alternative(html_content, "text/html")
msg.send()
Run Code Online (Sandbox Code Playgroud)
以上是发送电子邮件的视图.通过这种方式,我可以发送html内容和邮件,它发送电子邮件到[地址]单独,我想制作另一个密件抄送和cc也.我经历了Emailmessage objects
在文档中.我不知道如何包含bcc和cc来改变我的观点.
需要帮忙.
谢谢
settings.py
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'rakil@gmail.com'
EMAIL_HOST_PASSWORD = '*******'
DEFAULT_FROM_EMAIL = 'testing@testing.com
Run Code Online (Sandbox Code Playgroud)
但邮件没有发送到地址,在print.html
我点击send_email时打印机正在打印,但是它没有发送任何电子邮件.我正在使用Django 1.3.7和Python 2.6.
我不知道问题是版本还是一些逻辑问题.需要帮忙.
Date_Format = (
('0', ' dd / mm / yyyy'),
('1', 'mm / dd / yyyy'),
)
Time_Format = (
('0', ' 12 hour AM / PM '),
('1', ' 24 hour '),
)
class SettingsForm(forms.ModelForm):
date_format = forms.ChoiceField(widget=forms.RadioSelect(), choices=Date_Format)
time_format = forms.ChoiceField(widget=forms.RadioSelect(), choices=Time_Format)
Run Code Online (Sandbox Code Playgroud)
更新:
{% for radio in SettingsForm.date_format %}
{{ radio.choice_label }}
<div class="select">{{ radio.tag }}</div>
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
上面的表单将单选按钮呈现在无序列表中,但我希望无序列表.我怎么能这样做?
models.py是
from django.db import models
class Book(models.Model):
book_id=models.AutoField(primary_key=True,unique=True)
book_name=models.CharField(max_length=30)
author_name=models.CharField(max_length=30)
publisher_name=models.CharField(max_length=40)
class Meta:
db_table = u'Book'
def __unicode__(self):
return "%d %s %s %s" % (self.book_id,self.book_name, self.author_name,self.publisher_name)
Run Code Online (Sandbox Code Playgroud)
forms.py是
from django import forms
from django.forms import ModelForm
from myapp.models import Book
class BookForm(ModelForm):
class Meta:
model = Book
fields=['book_id','book_name','author_name','publisher_name']
Run Code Online (Sandbox Code Playgroud)
我的views.py是
def editbook(request,book_id):
queryset = Book.objects.filter(book_id=book_id)
if request.POST:
form=BookForm(request.POST,instance=queryset)
if form.is_valid():
form.save()
return redirect('index')
else:
form=BookForm(instance=queryset)
template = 'editbook.html'
book = { 'form':form }
return render_to_response(template, book , RequestContext(request))
Run Code Online (Sandbox Code Playgroud)
我需要编辑和更新数据库中已存在的数据行.我猜他们在views.py中存在一些问题.所以我不确定我的views.py是对的.请检查并告诉我是否有任何问题以及如何继续.
谢谢
的index.html
<td>{% if place or other_place or place_description%}{{ place}} {{ other_place}} {{place_description}}</td>
Run Code Online (Sandbox Code Playgroud)
这是在模板中显示所有数据.如果字符串长度超过80,我想截断它.
条件是,1.如果地方变量有超过80个字符,它应截断它们,不需要显示另外两个变量,如other_place和place_description.
2.如果放置变量和other_place变量超过80个字符,在这种情况下它应该从place_variable截断不需要显示place_description变量.
3.如果所有这三个都是他们的,而第80个字符是由place_description制作的,则需要截断他们的.
所有字段都不是必填字段,因此无论显示哪个字段,它都应该只显示80个字符.
需要帮助才能做到这一点.
谢谢
django django-templates django-models django-forms django-views
我想使用jQueryUI对话框在我的Django项目中添加一个功能,当你点击链接(如"删除"链接)时,会弹出一个jQueryUI对话框,询问你是否真的要删除该项.然后,如果单击删除按钮(找到jQuery对话框),Django函数将执行删除作业.
那么如何使删除按钮(找到jQuery对话框)发送一条帖子消息(带有相应的变量)到我的views.py中的Django函数,它将执行删除作业?
考虑我正在使用view.py文件(在Django中),如下所示
def deletebook(request,book_id):
books=Book.objects.get(pk=book_id)
books.delete()
return redirect('/index/')
Run Code Online (Sandbox Code Playgroud)
我的要求是如果我按下删除选项,立即出现一个确认对话框,其中包含2个字段,如下所示"是"或"否".
请帮我设计一个html页面和一个用jQuery开发的view.py页面.
我的HTML页面是
<form action="/deletebook/{{ books.book_id}}/" method="POST"> {% csrf_token %}
<table>
<tr>
<td align="right">Book Name :<br><br><br> </td>
<td align="left"><input type="text" name="book_name" value="{{books.book_name}}"></input><br><br><br></td>
</tr>
<tr>
<td align="right">Author Name :<br><br><br></td>
<td align="left"> <input type="text" name="author_name" value="{{books.author_name}}"></input><br><br><br></td>
</tr>
<tr>
<td align="right">Publisher Name : <br><br><br></td>
<td align="left"><input type="text" name="publisher_name" value="{{books.publisher_name}}"></input><br><br><br></td><br><br><br>
</tr>
</table>
<td><input type="submit" value="Delete"><td>
</form>
Run Code Online (Sandbox Code Playgroud) forms.py
class ImportExcelForm(Form):
file = forms.FileField(attrs={'class':'rounded_list',})
Run Code Online (Sandbox Code Playgroud)
我正在尝试将css类添加到我filefield
的表单中.我收到此错误"__init__() got an unexpected keyword argument 'attrs'"
我做错了什么.
谢谢
forms.py
DATE_INPUT_FORMAT = (
('%d/%m/%Y','%m/%d/%Y')
)
class ReportForm(forms.ModelForm):
manual_date = forms.DateField(input_formats = DATE_INPUT_FORMAT,
widget=forms.DateInput(format = '%d/%m/%Y'))
Run Code Online (Sandbox Code Playgroud)
1.Date格式应该根据数据库中的值进行更改,如果value在db中,则显示第一种格式,不显示,否则部分正在执行.
2.格式的变化取决于条件.
3.我在这里面临问题,如果输入格式为此(%m /%d /%Y),则在表单上,日期值将被交换并保存在数据库中.如果给定日期是07/06/2013 - > 2013年6月7日,在表格发布后,它将在2013年7月6日 - > 2013年7月6日在现场查看.它无法正常工作.
需要帮助来解决这个问题.
谢谢
在解析xml文件时,我得到以下回溯
ParseError at /addxml/
junk after document element: line 13, column 2
Request Method: POST
Request URL: http://localhost:8000/addxml/
Django Version: 1.3.7
Exception Type: ParseError
Exception Value:
junk after document element: line 13, column 2
Exception Location: /root/Samples/DemoApp/DemoApp/views.py in addxml, line 98
Python Executable: /usr/bin/python
Run Code Online (Sandbox Code Playgroud)
这是我的代码
if request.POST:
path = "{0}/app_name/filename.xml".format(settings.PROJECT_ROOT)
xmlDoc = open(path, 'r')
xmlDocData = xmlDoc.read()
xmlDocTree = etree.XML(xmlDocData)
Run Code Online (Sandbox Code Playgroud)
下面的行给出了错误
xmlDocTree = etree.XML(xmlDocData)
<book>
<book_id>101</book_id>
<book_name>Python</book_name>
<publisher_name>Maxwell</publisher_name>
<author_id>1002</author_id>
<first_name>John</first_name>
<last_name>Dezosa</last_name>
<email>john@gmail.com</email>
<age>34</age>
</book>
<book>
<book_id>102</book_id>
<book_name>Django</book_name>
<publisher_name>Technical</publisher_name>
<author_id>1003</author_id>
<first_name>Josep</first_name> …
Run Code Online (Sandbox Code Playgroud) django ×8
django-forms ×6
django-views ×6
jquery ×1
lxml ×1
mysql ×1
pip ×1
python ×1
python-2.7 ×1
xml ×1
xml-parsing ×1