<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<atom:link href="http://itecfun.com/extern.php?action=feed&amp;tid=3240&amp;type=rss" rel="self" type="application/rss+xml" />
		<title><![CDATA[个人知识管理站 / 重拾Python  Django web]]></title>
		<link>http://www.itecfun.com/viewtopic.php?id=3240</link>
		<description><![CDATA[重拾Python  Django web 最近发表的帖子。]]></description>
		<lastBuildDate>Fri, 17 Jun 2016 05:13:56 +0000</lastBuildDate>
		<generator>FluxBB</generator>
		<item>
			<title><![CDATA[Re: 重拾Python  Django web]]></title>
			<link>http://www.itecfun.com/viewtopic.php?pid=3461#p3461</link>
			<description><![CDATA[<p>Django 部署 <br /><a href="http://blog.csdn.net/yingmutongxue/article/details/43985559#" rel="nofollow">参考1</a><br /><a href="http://www.cnblogs.com/fnng/p/4119712.html" rel="nofollow">参考2</a></p><p>注意个软件版本需要相适应</p><p>已配置成功的软件环境如下：<br />Apache:httpd-2.4.20-x86-r2-VC9<br />Python:2.7.9 win32<br />Django:1.9.6<br />mod_wsgi:mod_wsgi-4.4.23+ap24vc9-cp27-cp27m-win32</p>]]></description>
			<author><![CDATA[dummy@example.com (xuyg)]]></author>
			<pubDate>Fri, 17 Jun 2016 05:13:56 +0000</pubDate>
			<guid>http://www.itecfun.com/viewtopic.php?pid=3461#p3461</guid>
		</item>
		<item>
			<title><![CDATA[Re: 重拾Python  Django web]]></title>
			<link>http://www.itecfun.com/viewtopic.php?pid=3460#p3460</link>
			<description><![CDATA[<p>问题：(1_8.W001) The standalone TEMPLATE_* settings were deprecated in Django 1.8 and the TEMPLATES dictionary takes precedence. You must put the values of the following settings into your default TEMPLATES dict: TEMPLATE_DEBUG.</p><p><strong><br />settings.py 文件如下:</strong></p><div class="codebox"><pre><code>DEBUG = True

TEMPLATE_DEBUG = DEBUG

TEMPLATES = [
    {
        &#039;BACKEND&#039;: &#039;django.template.backends.django.DjangoTemplates&#039;,
        &#039;DIRS&#039;: [os.path.join(BASE_DIR, &#039;myapp/templates&#039;)],
        &#039;APP_DIRS&#039;: True,
        &#039;OPTIONS&#039;: {
            &#039;context_processors&#039;: [
                &#039;django.template.context_processors.debug&#039;,
                &#039;django.template.context_processors.request&#039;,
                &#039;django.contrib.auth.context_processors.auth&#039;,
                &#039;django.contrib.messages.context_processors.messages&#039;,
            ],
            &#039;debug&#039;: DEBUG,
            &#039;DEBUG&#039;: DEBUG,
            &#039;TEMPLATE_DEBUG&#039;: DEBUG
        },
    }, ]</code></pre></div><p>修改为：<br />注释或删除<strong> TEMPLATE_DEBUG = DEBUG</strong></p><p>修改 TEMPLATES 如下</p><div class="codebox"><pre><code>DEBUG = True

TEMPLATES = [
    {
        ...
        &#039;OPTIONS&#039;: {
            &#039;debug&#039;: DEBUG,
        },
    },
]</code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (xuyg)]]></author>
			<pubDate>Fri, 17 Jun 2016 03:27:20 +0000</pubDate>
			<guid>http://www.itecfun.com/viewtopic.php?pid=3460#p3460</guid>
		</item>
		<item>
			<title><![CDATA[Re: 重拾Python  Django web]]></title>
			<link>http://www.itecfun.com/viewtopic.php?pid=3459#p3459</link>
			<description><![CDATA[<p>django-import-export <br /><a href="https://django-import-export.readthedocs.io/en/latest/installation.html" rel="nofollow">安装步骤</a> 经过实践发现该安装步骤在自己的电脑上装不上去，直接到github上下载zip包，把import_export文件夹拷贝到项目根目录下,再在按相关配置配即可。</p><p><a href="https://django-import-export.readthedocs.io/en/latest/getting_started.html" rel="nofollow">如何使用</a></p>]]></description>
			<author><![CDATA[dummy@example.com (xuyg)]]></author>
			<pubDate>Thu, 16 Jun 2016 00:42:21 +0000</pubDate>
			<guid>http://www.itecfun.com/viewtopic.php?pid=3459#p3459</guid>
		</item>
		<item>
			<title><![CDATA[Re: 重拾Python  Django web]]></title>
			<link>http://www.itecfun.com/viewtopic.php?pid=3458#p3458</link>
			<description><![CDATA[<p><a href="https://django-import-export.readthedocs.io/en/latest/installation.html" rel="nofollow">django-import-export</a><br /><strong>Installation and configuration</strong></p><p>django-import-export is available on the Python Package Index (PyPI), so it can be installed with standard Python tools like pip or easy_install:</p><div class="codebox"><pre><code>$ pip install django-import-export</code></pre></div><p>Alternatively, you can install the git repository directly to obtain the development version:</p><div class="codebox"><pre><code>$ pip install -e git+https://github.com/django-import-export/django-import-export.git#egg=django-import-export</code></pre></div><p>Now, you’re good to go, unless you want to use django-import-export from the admin as well. In this case, you need to add it to your INSTALLED_APPS and let Django collect its static files.</p><div class="codebox"><pre><code># settings.py
INSTALLED_APPS = (
    ...
    &#039;import_export&#039;,
)</code></pre></div><div class="codebox"><pre><code>$ python manage.py collectstatic</code></pre></div><p>All prequisites are set up! See Getting started to learn how to use django-import-export in your project.</p><p><strong>Settings</strong><br />You can use the following directives in your settings file:</p><div class="codebox"><pre><code>IMPORT_EXPORT_USE_TRANSACTIONS</code></pre></div><p>Global setting controls if resource importing should use database transactions. Default is False.</p><div class="codebox"><pre><code>IMPORT_EXPORT_SKIP_ADMIN_LOG</code></pre></div><p>Global setting controls if creating log entries for the admin changelist should be skipped when importing resource. The skip_admin_log attribute of ImportMixin is checked first, which defaults to None. If not found, this global option is used. This will speed up importing large datasets, but will lose changing logs in the admin changelist view. Default is False.</p><div class="codebox"><pre><code>IMPORT_EXPORT_TMP_STORAGE_CLASS</code></pre></div><p>Global setting for the class to use to handle temporary storage of the uploaded file when importing from the admin using an ImportMixin. The tmp_storage_class attribute of ImportMixin is checked first, which defaults to None. If not found, this global option is used. Default is <br /><strong>TempFolderStorage.</strong><br />Example app<br />There’s an example application that showcases what django-import-export can do. You can run it via:</p><div class="codebox"><pre><code>cd tests
./manage.py runserver</code></pre></div><p>Username and password for admin are<span style="color: red"> admin and password.</span></p>]]></description>
			<author><![CDATA[dummy@example.com (xuyg)]]></author>
			<pubDate>Tue, 14 Jun 2016 07:47:28 +0000</pubDate>
			<guid>http://www.itecfun.com/viewtopic.php?pid=3458#p3458</guid>
		</item>
		<item>
			<title><![CDATA[Re: 重拾Python  Django web]]></title>
			<link>http://www.itecfun.com/viewtopic.php?pid=3457#p3457</link>
			<description><![CDATA[<p><a href="https://docs.djangoproject.com/en/1.9/topics/db/models/" rel="nofollow">Django models</a></p>]]></description>
			<author><![CDATA[dummy@example.com (xuyg)]]></author>
			<pubDate>Tue, 14 Jun 2016 07:46:12 +0000</pubDate>
			<guid>http://www.itecfun.com/viewtopic.php?pid=3457#p3457</guid>
		</item>
		<item>
			<title><![CDATA[Re: 重拾Python  Django web]]></title>
			<link>http://www.itecfun.com/viewtopic.php?pid=3455#p3455</link>
			<description><![CDATA[<p>Django升级1.9.6出现的中文本地化bug<br />新版本的django包版本中只有zh_Hans目录，没有zh_CN,把zh_Hans目录复制一个zh_CN就Ok了</p>]]></description>
			<author><![CDATA[dummy@example.com (xuyg)]]></author>
			<pubDate>Mon, 06 Jun 2016 08:56:38 +0000</pubDate>
			<guid>http://www.itecfun.com/viewtopic.php?pid=3455#p3455</guid>
		</item>
		<item>
			<title><![CDATA[Re: 重拾Python  Django web]]></title>
			<link>http://www.itecfun.com/viewtopic.php?pid=3454#p3454</link>
			<description><![CDATA[<p>使用django-grappelli改善默认的django-admin后台</p><p>作者:&#160; &#160; liuzemin<br />时间:&#160; &#160; 2011-1-25<br />目录</p><p>1&#160; &#160;说明<br />2&#160; &#160;环境<br />3&#160; &#160;安装<br />3.1&#160; &#160;安装django<br />3.2&#160; &#160;安装django-greppelli<br />4&#160; &#160;配置<br />4.1&#160; &#160;配置seetings.py<br />4.2&#160; &#160;配置urls.py<br />4.3&#160; &#160;配置grapeelli静态文件目录<br />5&#160; &#160;启动<br />5.1&#160; &#160;启用admin管理后台<br />5.2&#160; &#160;配置启动参数，指定的adminmedia到grapelli静态文件目录<br />6&#160; &#160;其他资料<br />1&#160; &#160;说明<br />django-grappelli是django admin后台管理第三方美化插件，前端采用jquery等开发,美化后的界面，请移步（http://code.google.com/p/django-grappelli/wiki/screenshots ）查看</p><p>2&#160; &#160;环境<br />以下是我本机的测试环境:</p><p>Debian(lxde) Python:2.5.2 Django1.2.4 django-grappelli2.3<br />3&#160; &#160;安装<br />3.1&#160; &#160;安装django<br />略过（这个应该大家都会吧）</p><p>移步django官网下载，里面有详细的安装说明</p><p><a href="http://www.djangoproject.com/download/" rel="nofollow">http://www.djangoproject.com/download/</a></p><p>3.2&#160; &#160;安装django-greppelli<br />从code-google下载django-grappelli对应的版本 ( <a href="http://code.google.com/p/django-grappelli/downloads/list" rel="nofollow">http://code.google.com/p/django-grappel … loads/list</a> )，安装略过<br />如果安装了python的包管理器（setuptools）的话，采用easy_install -Z django-grappelli进行安装<br />4&#160; &#160;配置<br />4.1&#160; &#160;配置seetings.py<br />DATABASES = {<br />&#039;default&#039;: {<br />&#039;ENGINE&#039;: &#039;django.db.backends.sqlite3&#039;, # Add &#039;postgresql_psycopg2&#039;, &#039;postgresql&#039;, &#039;mysql&#039;, &#039;sqlite3&#039; or &#039;oracle&#039;.<br />&#039;NAME&#039;: &#039;/tmp/demo2.db&#039;, # Or path to database file if using sqlite3.#此处根据系统的不同指定名称目录，windows下直接使用绝对路径也可<br />&#039;USER&#039;: &#039;&#039;, # Not used with sqlite3.<br />&#039;PASSWORD&#039;: &#039;&#039;, # Not used with sqlite3.<br />&#039;HOST&#039;: &#039;&#039;, # Set to empty string for localhost. Not used with sqlite3.<br />&#039;PORT&#039;: &#039;&#039;, # Set to empty string for default. Not used with sqlite3.<br />}<br />} INSTALLED_APPS = (<br />&#039;grappelli&#039;,<br />&#039;django.contrib.auth&#039;,<br />&#039;django.contrib.contenttypes&#039;,<br />&#039;django.contrib.sessions&#039;,<br />&#039;django.contrib.sites&#039;,<br />&#039;django.contrib.messages&#039;,<br /># Uncomment the next line to enable the admin:<br />&#039;django.contrib.admin&#039;,<br /># Uncomment the next line to enable admin documentation:<br /># &#039;django.contrib.admindocs&#039;,<br />)<br />4.2&#160; &#160;配置urls.py<br />from django.contrib import admin<br />admin.autodiscover()<br />urlpatterns = patterns(&#039;&#039;,<br /># Example:<br /># (r&#039;^demo2/&#039;, include(&#039;demo2.foo.urls&#039;)),<br /># Uncomment the admin/doc line below to enable admin documentation:<br /># (r&#039;^admin/doc/&#039;, include(&#039;django.contrib.admindocs.urls&#039;)),<br /># Uncomment the next line to enable the admin:<br />(r&#039;^grappelli/&#039;,include(&#039;grappelli.urls&#039;)), #添加url映射<br />(r&#039;^admin/&#039;, include(admin.site.urls)),<br />)<br />4.3&#160; &#160;配置grapeelli静态文件目录<br />将安装好的grepeeli目录下的media复制到你项目位置或者其他指定位置</p><p>例如我的系统在:/usr/lib/python2.5/site-packages/django_grappelli-2.3-py2.5.egg/grappelli/media,windows下在c盘python对应版本目录</p><p>linux下使用复制命令到指定位置</p><p>cp -R /usr/lib/python2.5/site-packages/django_grappelli-2.3-py2.5.egg/grappelli/media /home/alex/test/demograpelli/static/</p><p>windows下自行复制site-packages下此插件对应的media目录到指定位置</p><p>5&#160; &#160;启动<br />5.1&#160; &#160;启用admin管理后台<br />使用python manage.py syncdb命令创建admin后台数据库,按照向导输入用户名邮箱及密码信息创建即可</p><p>输入完后可以使用python manage.py runserver启动服务</p><p>输入127.0.0.1:8000/admin/查看是否后台已有admin login界面，默认还是django自带的</p><p>5.2&#160; &#160;配置启动参数，指定的adminmedia到grapelli静态文件目录<br />使用</p><p>python manage.py runserver 192.168.17.235:8000 --adminmedia=/home/alex/test/demograpelli/static/</p><p>启动服务,adminmedia的目录根据个人系统设定相对路径即可,启动服务后，重新打开127.0.0.1:8000/admin/查看既有了grappelli后台管理了</p><p>6&#160; &#160;其他资料<br />关于此django插件的详细资料，请参考：http://readthedocs.org/docs/django-grappelli/en/latest/index.html</p><p>demo下载： <a href="http://www.zeuux.org/group/django/file/content/273/" rel="nofollow">http://www.zeuux.org/group/django/file/content/273/</a></p>]]></description>
			<author><![CDATA[dummy@example.com (xuyg)]]></author>
			<pubDate>Tue, 31 May 2016 04:42:28 +0000</pubDate>
			<guid>http://www.itecfun.com/viewtopic.php?pid=3454#p3454</guid>
		</item>
		<item>
			<title><![CDATA[Re: 重拾Python  Django web]]></title>
			<link>http://www.itecfun.com/viewtopic.php?pid=3453#p3453</link>
			<description><![CDATA[<p>django从数据库导出数据到excel表 (2012-10-24 14:21:40)转载▼<br />标签： python 杂谈&#160; &#160; 分类： 计算机技术<br />def exportAgencyCustomers(request):<br />&#160; &#160; response = HttpResponse(mimetype=&#039;application/vnd.ms-excel&#039;)<br />&#160; &#160; response[&#039;Content-Disposition&#039;] = &#039;attachment;filename=export_agencycustomer.xls&#039;<br />&#160; &#160; wb = xlwt.Workbook(encoding = &#039;utf-8&#039;)<br />&#160; &#160; sheet = wb.add_sheet(u&#039;订单&#039;)<br />&#160; &#160; #1st line&#160; &#160;<br />&#160; &#160; sheet.write(0,0, &#039;经销商编码&#039;)<br />&#160; &#160; sheet.write(0,1, &#039;经销商名称&#039;)<br />&#160; &#160; sheet.write(0,2, &#039;终端医院编码&#039;)<br />&#160; &#160; sheet.write(0,3, &#039;终端医院名称&#039;)<br />&#160; &#160;<br />&#160; &#160; row = 1<br />&#160; &#160; for agencycustomer in AgencyCustomer.objects.all():<br />&#160; &#160; &#160; &#160; sheet.write(row,0, agencycustomer.agency.cCusCode)<br />&#160; &#160; &#160; &#160; sheet.write(row,1, agencycustomer.agency.cCusName)<br />&#160; &#160; &#160; &#160; sheet.write(row,2, agencycustomer.cCusCode)<br />&#160; &#160; &#160; &#160; sheet.write(row,3, agencycustomer.cCusName)<br />&#160; &#160; &#160; &#160; row=row + 1<br />&#160; &#160; &#160; &#160;<br />&#160; &#160; output = StringIO.StringIO()<br />&#160; &#160; wb.save(output)<br />&#160; &#160; output.seek(0)<br />&#160; &#160; response.write(output.getvalue())<br />&#160; &#160; return response</p>]]></description>
			<author><![CDATA[dummy@example.com (xuyg)]]></author>
			<pubDate>Tue, 31 May 2016 04:41:43 +0000</pubDate>
			<guid>http://www.itecfun.com/viewtopic.php?pid=3453#p3453</guid>
		</item>
		<item>
			<title><![CDATA[Re: 重拾Python  Django web]]></title>
			<link>http://www.itecfun.com/viewtopic.php?pid=3452#p3452</link>
			<description><![CDATA[<p>django错误信息以及解决方法，有需要的朋友可以参考下。</p><p>1、错误信息：You&#039;re using the Django &quot;sites framework&quot; without having set the SITE_ID setting. Create a site in your database and set the SITE_ID setting to fix this error.<br />原因：settings.py里# Application definition中添加了&#039;django.contrib.sites&#039;模块后需要设置SITE_ID<br />处理：在settings.py里添加配置：SITE_ID = 1</p><p>2、错误信息：(1146, &quot;Table &#039;django_db.django_site&#039; doesn&#039;t exist&quot;)<br />原因：settings.py里# Application definition中添加了&#039;django.contrib.sites&#039;模块而没有创建相应的表<br />解决：python manage.py syncdb</p><p>3、访问html时提示UnicodeDecodeErroror等编码错误<br />解决：a、在数据库连接语句上添加：charset=&#039;utf8&#039;，对中文支持好一点。例如：conn=MySQLdb.connect(host=&quot;localhost&quot;, user=&quot;me&quot;, passwd=&quot;secret&quot;, db=&quot;mydb&quot;, charset=&#039;utf8&#039;)&quot;<br />b、在html文件中， 要加，否则如果数据库中的数据有汉字，访问html文件时就有可能会抛出编码异常问题。</p>]]></description>
			<author><![CDATA[dummy@example.com (xuyg)]]></author>
			<pubDate>Tue, 31 May 2016 00:48:11 +0000</pubDate>
			<guid>http://www.itecfun.com/viewtopic.php?pid=3452#p3452</guid>
		</item>
		<item>
			<title><![CDATA[Re: 重拾Python  Django web]]></title>
			<link>http://www.itecfun.com/viewtopic.php?pid=3451#p3451</link>
			<description><![CDATA[<p>models.py 文件</p><p># coding:utf8<br />from django.db import models</p><p>class Book(models.Model):<br />&#160; &#160; <br />&#160; &#160; name = models.CharField(max_length=255)<br />&#160; &#160; title = models.CharField(max_length=255)<br />&#160; &#160; price = models.IntegerField()<br />&#160; &#160; ...<br />&#160; &#160; <br />class Category(models.Model):<br />&#160; &#160; <br />&#160; &#160; CATEGORY_CHOICES = (<br />&#160; &#160; &#160; &#160; (&#039;00&#039;, &#039;English&#039;),<br />&#160; &#160; &#160; &#160; (&#039;01&#039;, &#039;Computer&#039;),<br />&#160; &#160; )<br />&#160; &#160; <br />&#160; &#160; book = models.ForeignKey(Book)<br />&#160; &#160; category = models.CharField(max_length=255, choices=CATEGORY_CHOICES)<br />&#160; &#160; remark = models.CharField(max_length=255)<br />&#160; &#160; ...</p><p>admin.py 文件（以 category 为例）</p><p># coding: utf8<br />from django.contrib import admin<br />from django import forms</p><p>from .models import Category</p><p>class CategoryAdmin(admin.ModelAdmin):</p><p>&#160; &#160; search_fileds = (&#039;book__name&#039;, &#039;book__title&#039;, &#039;book__price&#039;, &#039;category&#039;)&#160; # 设置搜索栏范围，如果有外键，要注明外键的哪个字段，双下划线<br />&#160; &#160; list_display = (&#039;book&#039;, &#039;category&#039;)&#160; # 在页面上显示的字段，若不设置则显示 models.py 中 __unicode__(self) 中所返回的值<br />&#160; &#160; list_display_links = (&#039;category&#039;)&#160; # 设置页面上哪个字段可单击进入详细页面<br />&#160; &#160; fields = (&#039;category&#039;, &#039;book&#039;)&#160; # 设置添加/修改详细信息时，哪些字段显示，在这里 remark 字段将不显示<br />&#160; &#160; <br />admin.site.register(Category, CategoryAdmin)</p><p>[说明]<br />在使用 Django admin 系统中的搜索时可能会出现“related Field has invalid lookup: icontains”错误，主要原因是外键查询是需要指定相应的字段的。外键不应该只是一个model，而该是另一个表的明确的一个字段。所以我们需要指定特定的字段 &quot;本表外键字段__外键所在表需查询字段&quot;。</p>]]></description>
			<author><![CDATA[dummy@example.com (xuyg)]]></author>
			<pubDate>Mon, 30 May 2016 10:18:03 +0000</pubDate>
			<guid>http://www.itecfun.com/viewtopic.php?pid=3451#p3451</guid>
		</item>
		<item>
			<title><![CDATA[重拾Python  Django web]]></title>
			<link>http://www.itecfun.com/viewtopic.php?pid=3450#p3450</link>
			<description><![CDATA[<p><a href="http://django-chinese-docs.readthedocs.io/en/latest/" rel="nofollow">http://django-chinese-docs.readthedocs.io/en/latest/</a></p><br /><p><a href="http://www.ibm.com/developerworks/cn/linux/l-django/" rel="nofollow">http://www.ibm.com/developerworks/cn/linux/l-django/</a></p><p><a href="http://www.ziqiangxuetang.com/django/django-cms-develop.html" rel="nofollow">http://www.ziqiangxuetang.com/django/dj … velop.html</a></p>]]></description>
			<author><![CDATA[dummy@example.com (xuyg)]]></author>
			<pubDate>Wed, 25 May 2016 06:55:27 +0000</pubDate>
			<guid>http://www.itecfun.com/viewtopic.php?pid=3450#p3450</guid>
		</item>
	</channel>
</rss>
