Logo video2dn
  • Сохранить видео с ютуба
  • Категории
    • Музыка
    • Кино и Анимация
    • Автомобили
    • Животные
    • Спорт
    • Путешествия
    • Игры
    • Люди и Блоги
    • Юмор
    • Развлечения
    • Новости и Политика
    • Howto и Стиль
    • Diy своими руками
    • Образование
    • Наука и Технологии
    • Некоммерческие Организации
  • О сайте

Скачать или смотреть Our First Django View

  • Code master
  • 2016-10-11
  • 3580
Our First Django View
First Django ViewDjango viewdjango renderdjango request and responseHow to query database in djangodjango first viewdjango rendering viewsdjango viewsdjango views.pyhow to load a view in django template15.our first django viewaccess views.py djangoadding views in djangodef post def get djangodjango cms tutorialdjango context and viewsdjango first htmldjango first template viewdjango first view renderdjango for loop views html
  • ok logo

Скачать Our First Django View бесплатно в качестве 4к (2к / 1080p)

У нас вы можете скачать бесплатно Our First Django View или посмотреть видео с ютуба в максимальном доступном качестве.

Для скачивания выберите вариант из формы ниже:

  • Информация по загрузке:

Cкачать музыку Our First Django View бесплатно в формате MP3:

Если иконки загрузки не отобразились, ПОЖАЛУЙСТА, НАЖМИТЕ ЗДЕСЬ или обновите страницу
Если у вас возникли трудности с загрузкой, пожалуйста, свяжитесь с нами по контактам, указанным в нижней части страницы.
Спасибо за использование сервиса video2dn.com

Описание к видео Our First Django View

Lesson 16 - Building Are First Django View
------------------------------------------
In this tutorial, we will build our first django view which will return all our blog post. If you are fimilar with wordpress or any blog type of application this is where we will see a list of blog post. Well atleast that is what we are going for in this tutorial.

1. Open up views.py. The views.py file recieves a request from the user and our code will return a response. So in short views handle request and response.

2. In the views.py file we see 'from django.shortcuts import render'. Render takes a request and returns the approiate template. So if the user request a list of blog post then render will take that response and return a template. You can think of a template as a html document which may contain some attentional context.

3. Now let's start creating our view. First we need access to our database so just like before we are going to add a import statement to access our database.
'from .models import Post'

4. Now we are going to create a function that will take a users request and return a response. So we will create a function called list_of_post.
'def list_of_post(request):'

5. Now what do we want to display? Well we want to display all our current blog post. How would we do that? We in the previous tutorial where I stressed how important it is to understand how to query the database this where it comes in. This next line of code will look very fimilar. Let's add this line
'post = Post.objects.all()' Post now represents all post in the database.

6. now we need to render the post per the request. How do we do this? We need to provide two arguments request and template name and then a third one we will use is often referred to as context.
request is coming from the url.py file bear with me on this one.
template name is going to be the location and name of html file we want to return.
context is going to all our post which is represent by the variable post.

putting it all together.
return render(request, 'blog/post/list_of_post.html', {'post': post})

Now that is how it should look per django documentation now I like to clean up my views a little more so they more uniformed. So what we are going to do is take the template and store that in a variable and the same with context. Final code will look like this.

def list_of_post(request):
post = Post.objects.all()
template = 'blog/post/list_of_post.html'
context = {'post': post}
return render(request, template, context)

Now we have create a first view there is not much we can do with it until we grab the users request and build a template to return the user.

Комментарии

Информация по комментариям в разработке

Похожие видео

  • О нас
  • Контакты
  • Отказ от ответственности - Disclaimer
  • Условия использования сайта - TOS
  • Политика конфиденциальности

video2dn Copyright © 2023 - 2025

Контакты для правообладателей [email protected]