Skip to content

Instantly share code, notes, and snippets.

#注释
shu=10000
result=[a for a in range(1,shu+1) if shu%a==0]
print(result)
@xiaotangyuan
xiaotangyuan / gist:c24707edfe9138b59f36
Last active August 29, 2015 14:02
计算当前文件夹下文件行数(代码量)
# coding=utf-8
import os
def countlines(thefile):
lines=0
with open(thefile) as f:
for line in f.readlines():
if len(line)>1:
# print line
lines=lines+1
@xiaotangyuan
xiaotangyuan / gist:8d5ce6fd8b6b6dba4832
Last active August 29, 2015 14:03
django的media_url、static_url
#媒体文件上传(本地)位置
MEDIA_ROOT=os.path.join(BASE_DIR,'moping/static/media/')
if ONLINE:
MEDIA_URL = 'http://mp360-img.stor.sinaapp.com/'
else:
MEDIA_URL = '/static/media/'
STATIC_ROOT = 'moping/static'
@xiaotangyuan
xiaotangyuan / gist:b791e8e958a37b039ffd
Created July 11, 2014 06:57
django多app的urls配置
# project下的urls.py
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'', include('account.urls')),
# url(r'^ac/', include('account.urls')),
)
#account的app下urls.py文件
urlpatterns = patterns('account.views',
url(r'^$','index',name='indexpage'),
@xiaotangyuan
xiaotangyuan / gist:af3d74dad49721e97b57
Last active August 29, 2015 14:05
django中模板格式化时间。
{{ datetimeField|date:'Y-m-d H:i' }}
{{ datetimeField|timesince }}
@xiaotangyuan
xiaotangyuan / gist:0e61f695e139faa52d6c
Created August 21, 2014 01:13
ForeignKey的related_name用法
class ProjectStyle(models.Model):
name=models.CharField(max_length=50)
def __unicode__(self):
return self.name
class GuanZhu(models.Model):
guanzhu=models.ForeignKey(ProjectStyle)
user=models.ForeignKey(BaseInfo,related_name='guanzhus')
# 可以通过在模板中如下使用
@xiaotangyuan
xiaotangyuan / gist:867a267dcccc0a60cda9
Created August 21, 2014 01:24
模板中的静态文件使用
# 在模板html文件顶部加入下面这行
{% load staticfiles %}
# 在使用静态文件的地方用:
<img src="{% static user.touxiang %}" />
@xiaotangyuan
xiaotangyuan / gist:e3e446cfe3208b081f04
Last active August 29, 2015 14:05
vim常见命令
#从第7行+后面4行,整体代码左移一个tab位置
7gg4<<
@xiaotangyuan
xiaotangyuan / gist:61d0403d269cda9a0c77
Created August 21, 2014 03:18
windows下安装pip-文件distribute_setup.py
#!python
"""Bootstrap distribute installation
If you want to use setuptools in your package's setup.py, just include this
file in the same directory with it, and add this to the top of your setup.py::
from distribute_setup import use_setuptools
use_setuptools()
If you want to require a specific version of setuptools, set a download
@xiaotangyuan
xiaotangyuan / gist:fb14d690e7a7deeb942a
Created August 21, 2014 03:19
windows下安装pip-文件get-pip.py
This file has been truncated, but you can view the full file.
#!/usr/bin/env python
#
# Hi There!
# You may be wondering what this giant blob of binary data here is, you might
# even be worried that we're up to something nefarious (good for you for being
# paranoid!). This is a base64 encoding of a zip file, this zip file contains
# an entire copy of pip.
#
# Pip is a thing that installs packages, pip itself is a package that someone
# might want to install, especially if they're looking to run this get-pip.py