install
emerge dev-python/pip
pip install django
create and switch to user
useradd django
su django
check the django information
python -c 'import django; print(django.get_version())'
project part
django-admin startproject mysite
cd mysite
python manage.py migrate
python manage.py runserver 0.0.0.0:8000
app part
python manage.py startapp polls
步骤:
1.< project >/setting.py/INSTALLED_APPS 添加app的名字
2.< project >/urls.py/urlpatterns 增加url(r'^admin/', include(admin.site.urls))
3.< app >/urls.py/urlpatterns 增加url(r'^$', views.index, name='index')
4.< app >/views.py 添加
def index(request):
return HttpResponse('main')
5.< app >/templates/< app >/ 里添加index.html等模版
6.< project >/setting.py/TEMPLATES.’DIRS’ 中添加
os.path.join(BASE_DIR, 'templates')
7.< app >/static/< app >/style.css
li a {
color: green;
}
8.图片放置:< app >/static/< app >/< images >/xxx.png