码迷,mamicode.com
首页 > 其他好文 > 详细

Collector

时间:2016-09-05 23:30:38      阅读:288      评论:0      收藏:0      [点我收藏+]

标签:

安装

参考安装文章

?

创建项目project

转到你创建的目录,运行命令

django-admin.py startproject collector

生成下列文件

collector/

__init__.py

manage.py

settings.py

urls.py

技术分享

?

Shell debug调试

python manage.py shell

>>> exit()

?

它背后是如何工作的: Django搜索DJANGO_SETTINGS_MODULE环境变量,它被设置在settings.py中。例如,假设collector在你的Python搜索路径中,那么DJANGO_SETTINGS_MODULE应该被设置为:‘collector.settings‘。

随着你越来越熟悉Django,你可能会偏向于废弃使用`` manage.py shell`` ,而是在你的配置文件.bash_profile中手动添加 DJANGO_SETTINGS_MODULE这个环境变量。

wsgi.py中

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "lwc.settings")

创建应用application

In future, whenever you need to activate an application for your project, you can simply add its package name to the INSTALLED_APPS variable. Depending on the application, you may also need to run python manage.py syncdb to create the application‘s data models in the database. After that, the application will become available in your projec

?

$python manage.py startapp joins

就会在工程目录下创建一个joins目录:

joins/

? ?? __init__.py

? ?? models.py

? ?? tests.py

? ?? views.py

?

如果想要沿用default的app,需要把它加到INSTALLED_APPS

INSTALLED_APPS = (

joins,

?

创建数据库

在settings.py中配置数据库

DATABASES = {

‘default‘: {

‘ENGINE‘: ‘django.db.backends.mysql‘, # Add ‘postgresql_psycopg2‘, ‘mysql‘, ‘sqlite3‘ or ‘oracle‘.

‘NAME‘: mydb, # Or path to database file if using sqlite3.

# The following settings are not used with sqlite3:

‘USER‘: ‘root‘,

‘PASSWORD‘: ‘123‘,

‘HOST‘: ‘‘, # Empty for localhost through domain sockets or ‘127.0.0.1‘ for localhost through TCP.

‘PORT‘: ‘‘, # Set to empty string for default.

}

}

执行下面命令同步数据库,它将会创建数据表和超级用户

$ python manage.py syncdb

?

调试模式

TEMPLATE_DEBUG = DEBUG = TRUE

?

启动服务器

可以用下面命令启动服务器,默认端口8000

python manage.py runserver

python manage.py runserver 8080

python manage.py runserver 0.0.0.0:8000

?

访问

http://127.0.0.1:8000/

虽然 django 自带的这个 web 服务器对于开发很方便,但是,千万不要在正式的应用布署环境中使用它。 在同一时间,该服务器只能可靠地处理一次单个请求,并且没有进行任何类型的安全审计。

?

第一个视图 – admin

setting.py

INSTALLED_APPS = (

# Uncomment the next line to enable the admin:

‘django.contrib.admin‘,

# Uncomment the next line to enable admin documentation:

‘django.contrib.admindocs‘,

)

urls.py

# Uncomment the next two lines to enable the admin:

from django.contrib import admin

admin.autodiscover()

?

urlpatterns = patterns(‘‘,

url(r‘^admin/‘, include(admin.site.urls)),

==>

url(r‘^admin/*‘, include(admin.site.urls)),

#add this *, otherwise, /admin will go to below next urlPattern, * means repeating precious char (0~n)

url(r‘^(?P<ref_id>.*)$‘, ‘joins.views.share‘, name=‘share‘),

)

?

Symbol / Expression

Matched String

. (Dot)?

Any character.?

^ (Caret)?

Start of string.?

$?

End of string.?

*?

0 or more repetitions.?

+?

1 or more repetitions.?

??

0 or 1 repetitions.

|?

A | B means A or B.?

[a-z]?

Any lowercase character.?

\w?

Any alphanumeric character or _.?

\d?

Any digit. ?

?

http://docs.python.org/lib/module-re.html

?

Collector

标签:

原文地址:http://www.cnblogs.com/2dogslife/p/5844052.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!