除了之前的一些 就外键 ForeignKey 还有日期 一些 格式
其他就是 讲的一些 注册 登录 欢迎XX登录 添加 转跳到外键id的页面 进行 修改删除
下面就是存代码
class CountryView(View):
def get(self,request):
date=Country.objects.all()
dix={‘info’:date}
return render(request,‘index.html’,dix)
{% endfor %}
</table>
编号 | 城市名 | 城市特点 | 所属国家 | 详细 |
{{ foo.id }} | {{ foo.name }} | {{ foo.te }} | {{ foo.suo }} | 删除 修改 |
from django.contrib import admin
from django.urls import path
from msyqll import views
urlpatterns = [
path(‘admin/’, admin.site.urls),
path(‘index/’,views.CountryView.as_view()),
path(‘fen/int:pk/’,views.cityViwe.as_view()),
path(‘del/int:pk/’,views.DelViwe.as_view()),
path(‘update/int:pk/’,views.UpdataViwe.as_view()),
]
class cityViwe(View):
def get(self,request,pk):
book=city.objects.filter(suo=pk)
desc={‘info’:book}
return render(request,‘fen.html’,desc)
class DelViwe(View):
def get(self,request,pk):
city.objects.filter(id=pk).delete()
return redirect(‘/fen/’)
还要注意那个 csrf的报错 403
加一个{{CSRF}} 或者在 settings里面 # ‘django.middleware.csrf.CsrfViewMiddleware’,
把这一句注释掉 防止csrf错误
报错
RuntimeError: ‘cryptography‘ package is required for sha256_password or caching_sha2_password auth m
执行 python manage.py runserver 时报错:
File "/Users/jason93/Desktop/PythonProject/django_drf/venv-djdrf/lib/python3.9/site-packages/pymysql/_auth.py", line 204, in sha2_rsa_encrypt
raise RuntimeError("'cryptography' package is required for sha256_password or caching_sha2_password auth methods")
RuntimeError: 'cryptography' package is required for sha256_password or caching_sha2_password auth methods
说 cryptography 这个包需要安装,则打开终端用pip进行安装,但发现安装不上:
(venv-djdrf) jason93@92 djangodrf % pip install cryptography
ERROR: Could not find a version that satisfies the requirement cryptography
ERROR: No matching distribution found for cryptography
(venv-djdrf) jason93@92 djangodrf %
然后打开setting在pip管理中下载
然后重新进行启动就好了