English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
سنقوم بإنشاء رؤية بسيطة في myapp لعرض: "welcome to w3codebox !"
انظر إلى النموذج التالي −
# Filename: example.py # Copyright: 2020 By w3codebox # Author by: ar.oldtoolbag.com # Date: 2020-08-08 from django.http import HttpResponse def hello(request): text = \ return HttpResponse(text)
في هذا الرؤية، نستخدم HttpResponse لعرض HTML (قد لاحظت أننا نقوم بتشيفر HTML في الرؤية). في هذه الرؤية، نحتاج فقط إلى توجيهها إلى صفحة URL (سيتم مناقشة ذلك في الفصول القادمة).
نستخدم HttpResponse قبل رسم HTML للعرض. هذا ليس أفضل طريقة لرسم صفحة الويب. يدعم Django نموذج MVT، حيث يتم رسم العرض أولاً، Django - MVT هو ما نحتاجه−
ملف قالب: myapp/templates/hello.html
الآن، محتوى عرضنا كالتالي −
# Filename: example.py # Copyright: 2020 By w3codebox # Author by: ar.oldtoolbag.com # Date: 2020-08-08 from django.shortcuts import render def hello(request): return render(request, "myapp/template/hello.html", {})
الم 参数 التي يمكن أن تقبلها العرض -
# Filename: example.py # Copyright: 2020 By w3codebox # Author by: ar.oldtoolbag.com # Date: 2020-08-08 from django.http import HttpResponse def hello(request, number): text = "<h1>welcome to my app number %s!</h1>"% number return HttpResponse(text)
عند ربط العنوان URL، سيتم عرض القيمة المرسلة كمعامل. ملاحظة، سيتم نقل المعامل عبر URL (في الفصل التالي).