这两天忙着收东西,准备出发去西部了,所以两天学习没进展。今天接着回顾之前做的项目:
-
Postgres
安装Postgres, 登陆Postgres:
sudo -u postgres psql
创建Database:
image.png
创建用户、密码:
image.png
修改settings:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'portfoliodb',
'USER': 'postgres',
'PASSWORD': 'django1234',
'HOST': 'localhost',
'PORT': '5432'
}
}
- How to check port:
当改变了database之后,需要重新建立superuser.
-
Blog Model
基本步骤:
-
create a Blog Model
-
add Blog app to settings
-
create a migration
-
migrate
-
add to Admin
-
Home Page
-
url
urlpatterns = [
path('', jobs.views.home,name='home'),
path('admin/', admin.site.urls),
path('blog/', include('blog.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Home page对应的jobs.views.home:
from django.shortcuts import render
from .models import Job
# Create your views here.
def home(request):
# get all job objects
jobs = Job.objects
return render(request,'jobs/home.html',{'jobs':jobs})
home.html放在project-->jobs-->templates-->jobs里面:
image.png-
Bootstrap
CSS放最前面:
image.png
js放最后:
image.png
Atom里的自动对齐:
image.png
网友评论