Re: TemplateDoesNotExist at /catalog/books/

2021-10-06 Thread Никита Назаров
Thank you so much!

ср, 6 окт. 2021 г. в 19:41, Adeyemi Deji :

> Hi, please make reference to link below, looks similar to what you are
> building
>
> https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/Generic_views
>
> Also I will read up the documentation to find solution to this issue. You
> can take a break, you have really worked hard today.
>
> On Wednesday, October 6, 2021 at 5:26:19 PM UTC+2 nazni...@gmail.com
> wrote:
>
>> No, both variants don't work.
>>
>> ср, 6 окт. 2021 г. в 18:17, Adeyemi Deji :
>>
>>> Okay, I also noticed something in the TEMPLATES VARIABLE in your
>>> settings.py file, please make DIRS an empty list like this [] with no space
>>> or better still change to [os.path.join(BASE_DIR, 'catalog/templates')]
>>>
>>> On Wednesday, October 6, 2021 at 5:00:42 PM UTC+2 nazni...@gmail.com
>>> wrote:
>>>
>>>> Thank you!
>>>> I corrected as you wrote. But I also have this mistake (
>>>> TemplateDoesNotExist at /catalog/books/
>>>> catalog/book_list.html, catalog/book_list.html).
>>>> Might I take the wrong path? (my path is below picture)
>>>> Also thank you for helping me. I am grateful to you. I have had this
>>>> problem for 1 week.
>>>> [image: image.png]
>>>>
>>>>
>>>> ср, 6 окт. 2021 г. в 16:19, Adeyemi Deji :
>>>>
>>>>> correct paginated_by to paginate_by.
>>>>>
>>>>>
>>>>> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon>
>>>>>  Virus-free.
>>>>> www.avast.com
>>>>> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link>
>>>>> <#m_5814264379585491325_m_-1143733024743841618_m_-1887519385446215222_m_-4865023885270008228_m_2700252164806904525_m_-6914425398611891894_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>>>>>
>>>>> On Wed, Oct 6, 2021 at 3:17 PM Adeyemi Deji 
>>>>> wrote:
>>>>>
>>>>>> Please correct your class views, you are getting it wrong.
>>>>>> it should look like this.
>>>>>>
>>>>>> class BookListView(generic.ListView):
>>>>>> model = Book
>>>>>> paginated_by = 10
>>>>>> template_name = "catalog/book_list.html"
>>>>>>
>>>>>> class BookDetailView(generic.DetailView):
>>>>>> model = Book
>>>>>> template_name = "catalog/book_detail.html"
>>>>>>
>>>>>>
>>>>>> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon>
>>>>>>  Virus-free.
>>>>>> www.avast.com
>>>>>> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link>
>>>>>> <#m_5814264379585491325_m_-1143733024743841618_m_-1887519385446215222_m_-4865023885270008228_m_2700252164806904525_m_-6914425398611891894_m_1024950781820118978_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>>>>>>
>>>>>> On Wed, Oct 6, 2021 at 3:09 PM Никита Назаров 
>>>>>> wrote:
>>>>>>
>>>>>>> It also doesn't work. I see this error :"TemplateDoesNotExist at
>>>>>>> /catalog/books/ catalog/book_list.html, catalog/book_list.html"
>>>>>>> My views.py is below.
>>>>>>> Also, I checked on GitHub Mozilla (
>>>>>>> https://github.com/mdn/django-locallibrary-tutorial/blob/master/catalog/views.py).
>>>>>>> They didn't use - template_name.
>>>>>>> I'm completely confused.
>>>>>>>
>>>>>>> from .models import Book, Author, BookInstance, Genre
>>>>>>> from django.views import generic
>>>>>>> from django.shortcuts import render
>>>>>>> from django.views.generic.base import TemplateView
>>>>>>>
>>>>>>> # Create your views here.
>>>>>>>
>>>>>>>
>>>>>>> def index(request):
>>>>>>> "&quo

Re: TemplateDoesNotExist at /catalog/books/

2021-10-06 Thread Adeyemi Deji
Hi, please make reference to link below, looks similar to what you are 
building
https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/Generic_views

Also I will read up the documentation to find solution to this issue. You 
can take a break, you have really worked hard today. 

On Wednesday, October 6, 2021 at 5:26:19 PM UTC+2 nazni...@gmail.com wrote:

> No, both variants don't work. 
>
> ср, 6 окт. 2021 г. в 18:17, Adeyemi Deji :
>
>> Okay, I also noticed something in the TEMPLATES VARIABLE in your 
>> settings.py file, please make DIRS an empty list like this [] with no space 
>> or better still change to [os.path.join(BASE_DIR, 'catalog/templates')]
>>
>> On Wednesday, October 6, 2021 at 5:00:42 PM UTC+2 nazni...@gmail.com 
>> wrote:
>>
>>> Thank you!
>>> I corrected as you wrote. But I also have this mistake (
>>> TemplateDoesNotExist at /catalog/books/
>>> catalog/book_list.html, catalog/book_list.html). 
>>> Might I take the wrong path? (my path is below picture)
>>> Also thank you for helping me. I am grateful to you. I have had this 
>>> problem for 1 week. 
>>> [image: image.png]
>>>
>>>
>>> ср, 6 окт. 2021 г. в 16:19, Adeyemi Deji :
>>>
>>>> correct paginated_by to paginate_by.
>>>>
>>>>
>>>> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon>
>>>>  Virus-free. 
>>>> www.avast.com 
>>>> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link>
>>>>  
>>>> <#m_-1143733024743841618_m_-1887519385446215222_m_-4865023885270008228_m_2700252164806904525_m_-6914425398611891894_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>>>>
>>>> On Wed, Oct 6, 2021 at 3:17 PM Adeyemi Deji  
>>>> wrote:
>>>>
>>>>> Please correct your class views, you are getting it wrong.
>>>>> it should look like this.
>>>>>
>>>>> class BookListView(generic.ListView):
>>>>> model = Book
>>>>> paginated_by = 10
>>>>> template_name = "catalog/book_list.html"
>>>>>
>>>>> class BookDetailView(generic.DetailView):
>>>>> model = Book
>>>>> template_name = "catalog/book_detail.html"
>>>>>
>>>>>
>>>>> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon>
>>>>>  Virus-free. 
>>>>> www.avast.com 
>>>>> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link>
>>>>>  
>>>>> <#m_-1143733024743841618_m_-1887519385446215222_m_-4865023885270008228_m_2700252164806904525_m_-6914425398611891894_m_1024950781820118978_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>>>>>
>>>>> On Wed, Oct 6, 2021 at 3:09 PM Никита Назаров  
>>>>> wrote:
>>>>>
>>>>>> It also doesn't work. I see this error :"TemplateDoesNotExist at 
>>>>>> /catalog/books/ catalog/book_list.html, catalog/book_list.html"
>>>>>> My views.py is below.
>>>>>> Also, I checked on GitHub Mozilla (
>>>>>> https://github.com/mdn/django-locallibrary-tutorial/blob/master/catalog/views.py).
>>>>>>  
>>>>>> They didn't use - template_name. 
>>>>>> I'm completely confused. 
>>>>>>
>>>>>> from .models import Book, Author, BookInstance, Genre
>>>>>> from django.views import generic
>>>>>> from django.shortcuts import render
>>>>>> from django.views.generic.base import TemplateView
>>>>>>
>>>>>> # Create your views here.
>>>>>>
>>>>>>
>>>>>> def index(request):
>>>>>> """View function for home page of site."""
>>>>>>
>>>>>> # Generate counts of some of the main objects
>>>>>> num_books = Book.objects.all().count()
>>>>>> num_instances = BookInstance.objects.all().count()
>>>>>>
>>>>>> # Available books (status

Re: TemplateDoesNotExist at /catalog/books/

2021-10-06 Thread Никита Назаров
No, both variants don't work.

ср, 6 окт. 2021 г. в 18:17, Adeyemi Deji :

> Okay, I also noticed something in the TEMPLATES VARIABLE in your
> settings.py file, please make DIRS an empty list like this [] with no space
> or better still change to [os.path.join(BASE_DIR, 'catalog/templates')]
>
> On Wednesday, October 6, 2021 at 5:00:42 PM UTC+2 nazni...@gmail.com
> wrote:
>
>> Thank you!
>> I corrected as you wrote. But I also have this mistake (
>> TemplateDoesNotExist at /catalog/books/
>> catalog/book_list.html, catalog/book_list.html).
>> Might I take the wrong path? (my path is below picture)
>> Also thank you for helping me. I am grateful to you. I have had this
>> problem for 1 week.
>> [image: image.png]
>>
>>
>> ср, 6 окт. 2021 г. в 16:19, Adeyemi Deji :
>>
>>> correct paginated_by to paginate_by.
>>>
>>>
>>> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon>
>>>  Virus-free.
>>> www.avast.com
>>> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link>
>>> <#m_-1887519385446215222_m_-4865023885270008228_m_2700252164806904525_m_-6914425398611891894_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>>>
>>> On Wed, Oct 6, 2021 at 3:17 PM Adeyemi Deji  wrote:
>>>
>>>> Please correct your class views, you are getting it wrong.
>>>> it should look like this.
>>>>
>>>> class BookListView(generic.ListView):
>>>> model = Book
>>>> paginated_by = 10
>>>> template_name = "catalog/book_list.html"
>>>>
>>>> class BookDetailView(generic.DetailView):
>>>> model = Book
>>>> template_name = "catalog/book_detail.html"
>>>>
>>>>
>>>> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon>
>>>>  Virus-free.
>>>> www.avast.com
>>>> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link>
>>>> <#m_-1887519385446215222_m_-4865023885270008228_m_2700252164806904525_m_-6914425398611891894_m_1024950781820118978_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>>>>
>>>> On Wed, Oct 6, 2021 at 3:09 PM Никита Назаров 
>>>> wrote:
>>>>
>>>>> It also doesn't work. I see this error :"TemplateDoesNotExist at
>>>>> /catalog/books/ catalog/book_list.html, catalog/book_list.html"
>>>>> My views.py is below.
>>>>> Also, I checked on GitHub Mozilla (
>>>>> https://github.com/mdn/django-locallibrary-tutorial/blob/master/catalog/views.py).
>>>>> They didn't use - template_name.
>>>>> I'm completely confused.
>>>>>
>>>>> from .models import Book, Author, BookInstance, Genre
>>>>> from django.views import generic
>>>>> from django.shortcuts import render
>>>>> from django.views.generic.base import TemplateView
>>>>>
>>>>> # Create your views here.
>>>>>
>>>>>
>>>>> def index(request):
>>>>> """View function for home page of site."""
>>>>>
>>>>> # Generate counts of some of the main objects
>>>>> num_books = Book.objects.all().count()
>>>>> num_instances = BookInstance.objects.all().count()
>>>>>
>>>>> # Available books (status = 'a')
>>>>> num_instances_available = BookInstance.objects.filter(
>>>>> status__exact='a').count()
>>>>>
>>>>> # The 'all()' is implied by default.
>>>>> num_authors = Author.objects.count()
>>>>>
>>>>> context = {
>>>>> 'num_books': num_books,
>>>>> 'num_instances': num_instances,
>>>>> 'num_instances_available': num_instances_available,
>>>>> 'num_authors': num_authors,
>>>>> }
>>>>>
>>>>> # Render the HTML template index.html with the data in the context
>>>>> variable
>>>>> return render(request, 'index.html', c

Re: TemplateDoesNotExist at /catalog/books/

2021-10-06 Thread Adeyemi Deji
Okay, I also noticed something in the TEMPLATES VARIABLE in your 
settings.py file, please make DIRS an empty list like this [] with no space 
or better still change to [os.path.join(BASE_DIR, 'catalog/templates')]

On Wednesday, October 6, 2021 at 5:00:42 PM UTC+2 nazni...@gmail.com wrote:

> Thank you!
> I corrected as you wrote. But I also have this mistake (
> TemplateDoesNotExist at /catalog/books/
> catalog/book_list.html, catalog/book_list.html). 
> Might I take the wrong path? (my path is below picture)
> Also thank you for helping me. I am grateful to you. I have had this 
> problem for 1 week. 
> [image: image.png]
>
>
> ср, 6 окт. 2021 г. в 16:19, Adeyemi Deji :
>
>> correct paginated_by to paginate_by.
>>
>>
>> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon>
>>  Virus-free. 
>> www.avast.com 
>> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link>
>>  
>> <#m_-4865023885270008228_m_2700252164806904525_m_-6914425398611891894_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>>
>> On Wed, Oct 6, 2021 at 3:17 PM Adeyemi Deji  wrote:
>>
>>> Please correct your class views, you are getting it wrong.
>>> it should look like this.
>>>
>>> class BookListView(generic.ListView):
>>> model = Book
>>> paginated_by = 10
>>> template_name = "catalog/book_list.html"
>>>
>>> class BookDetailView(generic.DetailView):
>>> model = Book
>>> template_name = "catalog/book_detail.html"
>>>
>>>
>>> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon>
>>>  Virus-free. 
>>> www.avast.com 
>>> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link>
>>>  
>>> <#m_-4865023885270008228_m_2700252164806904525_m_-6914425398611891894_m_1024950781820118978_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>>>
>>> On Wed, Oct 6, 2021 at 3:09 PM Никита Назаров  
>>> wrote:
>>>
>>>> It also doesn't work. I see this error :"TemplateDoesNotExist at 
>>>> /catalog/books/ catalog/book_list.html, catalog/book_list.html"
>>>> My views.py is below.
>>>> Also, I checked on GitHub Mozilla (
>>>> https://github.com/mdn/django-locallibrary-tutorial/blob/master/catalog/views.py).
>>>>  
>>>> They didn't use - template_name. 
>>>> I'm completely confused. 
>>>>
>>>> from .models import Book, Author, BookInstance, Genre
>>>> from django.views import generic
>>>> from django.shortcuts import render
>>>> from django.views.generic.base import TemplateView
>>>>
>>>> # Create your views here.
>>>>
>>>>
>>>> def index(request):
>>>> """View function for home page of site."""
>>>>
>>>> # Generate counts of some of the main objects
>>>> num_books = Book.objects.all().count()
>>>> num_instances = BookInstance.objects.all().count()
>>>>
>>>> # Available books (status = 'a')
>>>> num_instances_available = BookInstance.objects.filter(
>>>> status__exact='a').count()
>>>>
>>>> # The 'all()' is implied by default.
>>>> num_authors = Author.objects.count()
>>>>
>>>> context = {
>>>> 'num_books': num_books,
>>>> 'num_instances': num_instances,
>>>> 'num_instances_available': num_instances_available,
>>>> 'num_authors': num_authors,
>>>> }
>>>>
>>>> # Render the HTML template index.html with the data in the context 
>>>> variable
>>>> return render(request, 'index.html', context=context)
>>>>
>>>>
>>>> class BookListView(generic.ListView):
>>>>
>>>> """Generic class-based view for a list of books."""
>>>>
>>>> model = Book
>>>> paginate_by = 10
>>>> template_name = "catalog/book_list.html"
>>>>
>>>>
>>>> class BookDetailView(

Re: TemplateDoesNotExist at /catalog/books/

2021-10-06 Thread Adeyemi Deji
correct paginated_by to paginate_by.

<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon>
Virus-free.
www.avast.com
<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

On Wed, Oct 6, 2021 at 3:17 PM Adeyemi Deji  wrote:

> Please correct your class views, you are getting it wrong.
> it should look like this.
>
> class BookListView(generic.ListView):
> model = Book
> paginated_by = 10
> template_name = "catalog/book_list.html"
>
> class BookDetailView(generic.DetailView):
> model = Book
> template_name = "catalog/book_detail.html"
>
>
> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon>
>  Virus-free.
> www.avast.com
> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link>
> <#m_1024950781820118978_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>
> On Wed, Oct 6, 2021 at 3:09 PM Никита Назаров 
> wrote:
>
>> It also doesn't work. I see this error :"TemplateDoesNotExist at
>> /catalog/books/ catalog/book_list.html, catalog/book_list.html"
>> My views.py is below.
>> Also, I checked on GitHub Mozilla (
>> https://github.com/mdn/django-locallibrary-tutorial/blob/master/catalog/views.py).
>> They didn't use - template_name.
>> I'm completely confused.
>>
>> from .models import Book, Author, BookInstance, Genre
>> from django.views import generic
>> from django.shortcuts import render
>> from django.views.generic.base import TemplateView
>>
>> # Create your views here.
>>
>>
>> def index(request):
>> """View function for home page of site."""
>>
>> # Generate counts of some of the main objects
>> num_books = Book.objects.all().count()
>> num_instances = BookInstance.objects.all().count()
>>
>> # Available books (status = 'a')
>> num_instances_available = BookInstance.objects.filter(
>> status__exact='a').count()
>>
>> # The 'all()' is implied by default.
>> num_authors = Author.objects.count()
>>
>> context = {
>> 'num_books': num_books,
>> 'num_instances': num_instances,
>> 'num_instances_available': num_instances_available,
>> 'num_authors': num_authors,
>> }
>>
>> # Render the HTML template index.html with the data in the context
>> variable
>> return render(request, 'index.html', context=context)
>>
>>
>> class BookListView(generic.ListView):
>>
>> """Generic class-based view for a list of books."""
>>
>> model = Book
>> paginate_by = 10
>> template_name = "catalog/book_list.html"
>>
>>
>> class BookDetailView(generic.DetailView):
>>
>> """Generic class-based detail view for a book."""
>> model = Book
>> template_name = "catalog/book_detail.html"
>>
>>
>>
>> ср, 6 окт. 2021 г. в 14:24, Adeyemi Deji :
>>
>>> class BookListView(generic.ListView):
>>>
>>> """Generic class-based view for a list of books."""
>>>
>>> model = Book
>>>
>>> paginate_by = 10
>>>
>>> template_name = "catalog/book_list.html"
>>>
>>>
>>> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon>
>>>  Virus-free.
>>> www.avast.com
>>> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link>
>>> <#m_1024950781820118978_m_8455319138707163929_m_3791702616293114032_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>>>
>>> On Wed, Oct 6, 2021 at 1:21 PM Adeyemi Deji 
>>> wrote:
>>>
>>>> Please don't change your formal code setting, just add the
>>>> template_name attribute and specify the template you are referring to
>>>> just add this to your former code:
>>>> template_name = "catalog/book_list.html"
>>>>
>>>>
>>>> <https://www.avas

Re: TemplateDoesNotExist at /catalog/books/

2021-10-06 Thread Adeyemi Deji
Please correct your class views, you are getting it wrong.
it should look like this.

class BookListView(generic.ListView):
model = Book
paginated_by = 10
template_name = "catalog/book_list.html"

class BookDetailView(generic.DetailView):
model = Book
template_name = "catalog/book_detail.html"

<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon>
Virus-free.
www.avast.com
<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

On Wed, Oct 6, 2021 at 3:09 PM Никита Назаров  wrote:

> It also doesn't work. I see this error :"TemplateDoesNotExist at
> /catalog/books/ catalog/book_list.html, catalog/book_list.html"
> My views.py is below.
> Also, I checked on GitHub Mozilla (
> https://github.com/mdn/django-locallibrary-tutorial/blob/master/catalog/views.py).
> They didn't use - template_name.
> I'm completely confused.
>
> from .models import Book, Author, BookInstance, Genre
> from django.views import generic
> from django.shortcuts import render
> from django.views.generic.base import TemplateView
>
> # Create your views here.
>
>
> def index(request):
> """View function for home page of site."""
>
> # Generate counts of some of the main objects
> num_books = Book.objects.all().count()
> num_instances = BookInstance.objects.all().count()
>
> # Available books (status = 'a')
> num_instances_available = BookInstance.objects.filter(
> status__exact='a').count()
>
> # The 'all()' is implied by default.
> num_authors = Author.objects.count()
>
> context = {
> 'num_books': num_books,
> 'num_instances': num_instances,
> 'num_instances_available': num_instances_available,
> 'num_authors': num_authors,
> }
>
> # Render the HTML template index.html with the data in the context variable
> return render(request, 'index.html', context=context)
>
>
> class BookListView(generic.ListView):
>
> """Generic class-based view for a list of books."""
>
> model = Book
> paginate_by = 10
> template_name = "catalog/book_list.html"
>
>
> class BookDetailView(generic.DetailView):
>
> """Generic class-based detail view for a book."""
> model = Book
> template_name = "catalog/book_detail.html"
>
>
>
> ср, 6 окт. 2021 г. в 14:24, Adeyemi Deji :
>
>> class BookListView(generic.ListView):
>>
>> """Generic class-based view for a list of books."""
>>
>> model = Book
>>
>> paginate_by = 10
>>
>> template_name = "catalog/book_list.html"
>>
>>
>> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon>
>>  Virus-free.
>> www.avast.com
>> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link>
>> <#m_8455319138707163929_m_3791702616293114032_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>>
>> On Wed, Oct 6, 2021 at 1:21 PM Adeyemi Deji 
>> wrote:
>>
>>> Please don't change your formal code setting, just add the template_name
>>> attribute and specify the template you are referring to
>>> just add this to your former code:
>>> template_name = "catalog/book_list.html"
>>>
>>>
>>> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon>
>>>  Virus-free.
>>> www.avast.com
>>> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link>
>>> <#m_8455319138707163929_m_3791702616293114032_m_2104138296797754165_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>>>
>>> On Wed, Oct 6, 2021 at 1:09 PM Никита Назаров 
>>> wrote:
>>>
>>>> It doesn't seem to work. I wrote your example in views.py.
>>>> Or I might make mistakes. Could you see?
>>>>
>>>> views. py
>>>> from .models import Book, Author, BookInstance, Genre
>>>> from django.views import generic
>>>> from django.shortcuts import render
>>>> from djang

Re: TemplateDoesNotExist at /catalog/books/

2021-10-06 Thread Никита Назаров
It also doesn't work. I see this error :"TemplateDoesNotExist at
/catalog/books/ catalog/book_list.html, catalog/book_list.html"
My views.py is below.
Also, I checked on GitHub Mozilla (
https://github.com/mdn/django-locallibrary-tutorial/blob/master/catalog/views.py).
They didn't use - template_name.
I'm completely confused.

from .models import Book, Author, BookInstance, Genre
from django.views import generic
from django.shortcuts import render
from django.views.generic.base import TemplateView

# Create your views here.


def index(request):
"""View function for home page of site."""

# Generate counts of some of the main objects
num_books = Book.objects.all().count()
num_instances = BookInstance.objects.all().count()

# Available books (status = 'a')
num_instances_available = BookInstance.objects.filter(
status__exact='a').count()

# The 'all()' is implied by default.
num_authors = Author.objects.count()

context = {
'num_books': num_books,
'num_instances': num_instances,
'num_instances_available': num_instances_available,
'num_authors': num_authors,
}

# Render the HTML template index.html with the data in the context variable
return render(request, 'index.html', context=context)


class BookListView(generic.ListView):

"""Generic class-based view for a list of books."""

model = Book
paginate_by = 10
template_name = "catalog/book_list.html"


class BookDetailView(generic.DetailView):

"""Generic class-based detail view for a book."""
model = Book
template_name = "catalog/book_detail.html"



ср, 6 окт. 2021 г. в 14:24, Adeyemi Deji :

> class BookListView(generic.ListView):
>
> """Generic class-based view for a list of books."""
>
> model = Book
>
> paginate_by = 10
>
> template_name = "catalog/book_list.html"
>
>
> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon>
>  Virus-free.
> www.avast.com
> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link>
> <#m_3791702616293114032_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>
> On Wed, Oct 6, 2021 at 1:21 PM Adeyemi Deji 
> wrote:
>
>> Please don't change your formal code setting, just add the template_name
>> attribute and specify the template you are referring to
>> just add this to your former code:
>> template_name = "catalog/book_list.html"
>>
>>
>> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon>
>>  Virus-free.
>> www.avast.com
>> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link>
>> <#m_3791702616293114032_m_2104138296797754165_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>>
>> On Wed, Oct 6, 2021 at 1:09 PM Никита Назаров 
>> wrote:
>>
>>> It doesn't seem to work. I wrote your example in views.py.
>>> Or I might make mistakes. Could you see?
>>>
>>> views. py
>>> from .models import Book, Author, BookInstance, Genre
>>> from django.views import generic
>>> from django.shortcuts import render
>>> from django.views.generic.base import TemplateView
>>>
>>> # Create your views here.
>>>
>>>
>>> def index(request):
>>> """View function for home page of site."""
>>>
>>> # Generate counts of some of the main objects
>>> num_books = Book.objects.all().count()
>>> num_instances = BookInstance.objects.all().count()
>>>
>>> # Available books (status = 'a')
>>> num_instances_available = BookInstance.objects.filter(
>>> status__exact='a').count()
>>>
>>> # The 'all()' is implied by default.
>>> num_authors = Author.objects.count()
>>>
>>> context = {
>>> 'num_books': num_books,
>>> 'num_instances': num_instances,
>>> 'num_instances_available': num_instances_available,
>>> 'num_authors': num_authors,
>>> }
>>>
>>> # Render the HTML template index.html with the data in the context
>>> variable
>>> return render(request, 'catalog/index.html', context=context)
>>>
>>>
>>> class BookListView(Templa

Re: TemplateDoesNotExist at /catalog/books/

2021-10-06 Thread Adeyemi Deji
class BookListView(generic.ListView):

"""Generic class-based view for a list of books."""

model = Book

paginate_by = 10

template_name = "catalog/book_list.html"

<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon>
Virus-free.
www.avast.com
<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

On Wed, Oct 6, 2021 at 1:21 PM Adeyemi Deji  wrote:

> Please don't change your formal code setting, just add the template_name
> attribute and specify the template you are referring to
> just add this to your former code:
> template_name = "catalog/book_list.html"
>
>
> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon>
>  Virus-free.
> www.avast.com
> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link>
> <#m_2104138296797754165_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>
> On Wed, Oct 6, 2021 at 1:09 PM Никита Назаров 
> wrote:
>
>> It doesn't seem to work. I wrote your example in views.py.
>> Or I might make mistakes. Could you see?
>>
>> views. py
>> from .models import Book, Author, BookInstance, Genre
>> from django.views import generic
>> from django.shortcuts import render
>> from django.views.generic.base import TemplateView
>>
>> # Create your views here.
>>
>>
>> def index(request):
>> """View function for home page of site."""
>>
>> # Generate counts of some of the main objects
>> num_books = Book.objects.all().count()
>> num_instances = BookInstance.objects.all().count()
>>
>> # Available books (status = 'a')
>> num_instances_available = BookInstance.objects.filter(
>> status__exact='a').count()
>>
>> # The 'all()' is implied by default.
>> num_authors = Author.objects.count()
>>
>> context = {
>> 'num_books': num_books,
>> 'num_instances': num_instances,
>> 'num_instances_available': num_instances_available,
>> 'num_authors': num_authors,
>> }
>>
>> # Render the HTML template index.html with the data in the context
>> variable
>> return render(request, 'catalog/index.html', context=context)
>>
>>
>> class BookListView(TemplateView):
>> template_name = "catalog/book_list.html"
>>
>>
>> class BookDetailView(TemplateView):
>> template_name = "catalog/book_detail.html"
>>
>>
>> urls.py
>> from django.urls import path
>> from . import views
>>
>>
>> urlpatterns = [
>> path('', views.index, name='index'),
>> path('books/', views.BookListView.as_view(), name='books'),
>> path('book/', views.BookDetailView.as_view(), name='book-detail'
>> ),
>> ]
>>
>>
>>
>>
>> ср, 6 окт. 2021 г. в 12:45, Adeyemi Deji :
>>
>>> for example.
>>>
>>> class AboutView(TemplateView):
>>> template_name = "about.html"
>>>
>>>
>>> On Wed, Oct 6, 2021 at 11:32 AM Никита Назаров 
>>> wrote:
>>>
>>>> Hello!
>>>> Thank you!
>>>> I'm sorry. How could I do this?
>>>>
>>>> среда, 6 октября 2021 г. в 11:20:19 UTC+3, adeyem...@gmail.com:
>>>>
>>>>> Hi, I observed that you didn't specify the template name attribute for
>>>>> the BookListView and BookDetailView, that should solve you problem.
>>>>>
>>>>> On Tuesday, October 5, 2021 at 10:37:19 PM UTC+2 nazni...@gmail.com
>>>>> wrote:
>>>>>
>>>>>> Hello!
>>>>>> I’m beginner in Django. I do Django Tutorial from Mozilla.
>>>>>> I get TemplateDoesNotExist at /catalog/books/ . Could you help me?. I
>>>>>> don’t understand how to resolve it.
>>>>>>
>>>>>> */catalog/urls*
>>>>>>
>>>>>> from django.urls import path
>>>>>>
>>>>>> from . import views
>>>>>>
>>>>>> urlpatterns = [
>>>>>>
>>>>>>   

Re: TemplateDoesNotExist at /catalog/books/

2021-10-06 Thread Adeyemi Deji
Please don't change your formal code setting, just add the template_name
attribute and specify the template you are referring to
just add this to your former code:
template_name = "catalog/book_list.html"

<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon>
Virus-free.
www.avast.com
<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

On Wed, Oct 6, 2021 at 1:09 PM Никита Назаров  wrote:

> It doesn't seem to work. I wrote your example in views.py.
> Or I might make mistakes. Could you see?
>
> views. py
> from .models import Book, Author, BookInstance, Genre
> from django.views import generic
> from django.shortcuts import render
> from django.views.generic.base import TemplateView
>
> # Create your views here.
>
>
> def index(request):
> """View function for home page of site."""
>
> # Generate counts of some of the main objects
> num_books = Book.objects.all().count()
> num_instances = BookInstance.objects.all().count()
>
> # Available books (status = 'a')
> num_instances_available = BookInstance.objects.filter(
> status__exact='a').count()
>
> # The 'all()' is implied by default.
> num_authors = Author.objects.count()
>
> context = {
> 'num_books': num_books,
> 'num_instances': num_instances,
> 'num_instances_available': num_instances_available,
> 'num_authors': num_authors,
> }
>
> # Render the HTML template index.html with the data in the context variable
> return render(request, 'catalog/index.html', context=context)
>
>
> class BookListView(TemplateView):
> template_name = "catalog/book_list.html"
>
>
> class BookDetailView(TemplateView):
> template_name = "catalog/book_detail.html"
>
>
> urls.py
> from django.urls import path
> from . import views
>
>
> urlpatterns = [
> path('', views.index, name='index'),
> path('books/', views.BookListView.as_view(), name='books'),
> path('book/', views.BookDetailView.as_view(), name='book-detail'),
> ]
>
>
>
>
> ср, 6 окт. 2021 г. в 12:45, Adeyemi Deji :
>
>> for example.
>>
>> class AboutView(TemplateView):
>> template_name = "about.html"
>>
>>
>> On Wed, Oct 6, 2021 at 11:32 AM Никита Назаров 
>> wrote:
>>
>>> Hello!
>>> Thank you!
>>> I'm sorry. How could I do this?
>>>
>>> среда, 6 октября 2021 г. в 11:20:19 UTC+3, adeyem...@gmail.com:
>>>
>>>> Hi, I observed that you didn't specify the template name attribute for
>>>> the BookListView and BookDetailView, that should solve you problem.
>>>>
>>>> On Tuesday, October 5, 2021 at 10:37:19 PM UTC+2 nazni...@gmail.com
>>>> wrote:
>>>>
>>>>> Hello!
>>>>> I’m beginner in Django. I do Django Tutorial from Mozilla.
>>>>> I get TemplateDoesNotExist at /catalog/books/ . Could you help me?. I
>>>>> don’t understand how to resolve it.
>>>>>
>>>>> */catalog/urls*
>>>>>
>>>>> from django.urls import path
>>>>>
>>>>> from . import views
>>>>>
>>>>> urlpatterns = [
>>>>>
>>>>> path('', views.index, name='index'),
>>>>>
>>>>> path('books/', views.BookListView.as_view(), name='books'),
>>>>>
>>>>> path('book/', views.BookDetailView.as_view(),
>>>>> name='book-detail'),
>>>>>
>>>>> ]
>>>>>
>>>>> *catalog/models*
>>>>>
>>>>> # Used to generate URLs by reversing the URL patterns
>>>>>
>>>>> from django.urls import reverse
>>>>>
>>>>> from django.db import models
>>>>>
>>>>> from django.urls import reverse
>>>>>
>>>>> import uuid
>>>>>
>>>>> # Create your models here
>>>>>
>>>>> class Genre(models.Model):
>>>>>
>>>>> """Model representing a book genre (e.g. Science Fiction, Non
>>>>> Fiction)."""
>>>>>

Re: TemplateDoesNotExist at /catalog/books/

2021-10-06 Thread Никита Назаров
It doesn't seem to work. I wrote your example in views.py.
Or I might make mistakes. Could you see?

views. py
from .models import Book, Author, BookInstance, Genre
from django.views import generic
from django.shortcuts import render
from django.views.generic.base import TemplateView

# Create your views here.


def index(request):
"""View function for home page of site."""

# Generate counts of some of the main objects
num_books = Book.objects.all().count()
num_instances = BookInstance.objects.all().count()

# Available books (status = 'a')
num_instances_available = BookInstance.objects.filter(
status__exact='a').count()

# The 'all()' is implied by default.
num_authors = Author.objects.count()

context = {
'num_books': num_books,
'num_instances': num_instances,
'num_instances_available': num_instances_available,
'num_authors': num_authors,
}

# Render the HTML template index.html with the data in the context variable
return render(request, 'catalog/index.html', context=context)


class BookListView(TemplateView):
template_name = "catalog/book_list.html"


class BookDetailView(TemplateView):
template_name = "catalog/book_detail.html"


urls.py
from django.urls import path
from . import views


urlpatterns = [
path('', views.index, name='index'),
path('books/', views.BookListView.as_view(), name='books'),
path('book/', views.BookDetailView.as_view(), name='book-detail'),
]




ср, 6 окт. 2021 г. в 12:45, Adeyemi Deji :

> for example.
>
> class AboutView(TemplateView):
> template_name = "about.html"
>
>
> On Wed, Oct 6, 2021 at 11:32 AM Никита Назаров 
> wrote:
>
>> Hello!
>> Thank you!
>> I'm sorry. How could I do this?
>>
>> среда, 6 октября 2021 г. в 11:20:19 UTC+3, adeyem...@gmail.com:
>>
>>> Hi, I observed that you didn't specify the template name attribute for
>>> the BookListView and BookDetailView, that should solve you problem.
>>>
>>> On Tuesday, October 5, 2021 at 10:37:19 PM UTC+2 nazni...@gmail.com
>>> wrote:
>>>
>>>> Hello!
>>>> I’m beginner in Django. I do Django Tutorial from Mozilla.
>>>> I get TemplateDoesNotExist at /catalog/books/ . Could you help me?. I
>>>> don’t understand how to resolve it.
>>>>
>>>> */catalog/urls*
>>>>
>>>> from django.urls import path
>>>>
>>>> from . import views
>>>>
>>>> urlpatterns = [
>>>>
>>>> path('', views.index, name='index'),
>>>>
>>>> path('books/', views.BookListView.as_view(), name='books'),
>>>>
>>>> path('book/', views.BookDetailView.as_view(),
>>>> name='book-detail'),
>>>>
>>>> ]
>>>>
>>>> *catalog/models*
>>>>
>>>> # Used to generate URLs by reversing the URL patterns
>>>>
>>>> from django.urls import reverse
>>>>
>>>> from django.db import models
>>>>
>>>> from django.urls import reverse
>>>>
>>>> import uuid
>>>>
>>>> # Create your models here
>>>>
>>>> class Genre(models.Model):
>>>>
>>>> """Model representing a book genre (e.g. Science Fiction, Non
>>>> Fiction)."""
>>>>
>>>> name = models.CharField(
>>>>
>>>> max_length=200,
>>>>
>>>> help_text="Enter a book genre (e.g. Science Fiction, French
>>>> Poetry etc.)"
>>>>
>>>> )
>>>>
>>>> def __str__(self):
>>>>
>>>> """String for representing the Model object (in Admin site
>>>> etc.)"""
>>>>
>>>> return self.name
>>>>
>>>> class Book(models.Model):
>>>>
>>>> """Model representing a book (but not a specific copy of a book)."""
>>>>
>>>> title = models.CharField(max_length=200)
>>>>
>>>> author = models.ForeignKey('Author', on_delete=models.SET_NULL,
>>>> null=True)
>>>>
>>>> # Foreign Key used because book can only have one author, but
>>>> authors can have multiple books
>>>>
>>>> # Author a

Re: TemplateDoesNotExist at /catalog/books/

2021-10-06 Thread Adeyemi Deji
for example.

class AboutView(TemplateView):
template_name = "about.html"


On Wed, Oct 6, 2021 at 11:32 AM Никита Назаров 
wrote:

> Hello!
> Thank you!
> I'm sorry. How could I do this?
>
> среда, 6 октября 2021 г. в 11:20:19 UTC+3, adeyem...@gmail.com:
>
>> Hi, I observed that you didn't specify the template name attribute for
>> the BookListView and BookDetailView, that should solve you problem.
>>
>> On Tuesday, October 5, 2021 at 10:37:19 PM UTC+2 nazni...@gmail.com
>> wrote:
>>
>>> Hello!
>>> I’m beginner in Django. I do Django Tutorial from Mozilla.
>>> I get TemplateDoesNotExist at /catalog/books/ . Could you help me?. I
>>> don’t understand how to resolve it.
>>>
>>> */catalog/urls*
>>>
>>> from django.urls import path
>>>
>>> from . import views
>>>
>>> urlpatterns = [
>>>
>>> path('', views.index, name='index'),
>>>
>>> path('books/', views.BookListView.as_view(), name='books'),
>>>
>>> path('book/', views.BookDetailView.as_view(),
>>> name='book-detail'),
>>>
>>> ]
>>>
>>> *catalog/models*
>>>
>>> # Used to generate URLs by reversing the URL patterns
>>>
>>> from django.urls import reverse
>>>
>>> from django.db import models
>>>
>>> from django.urls import reverse
>>>
>>> import uuid
>>>
>>> # Create your models here
>>>
>>> class Genre(models.Model):
>>>
>>> """Model representing a book genre (e.g. Science Fiction, Non
>>> Fiction)."""
>>>
>>> name = models.CharField(
>>>
>>> max_length=200,
>>>
>>> help_text="Enter a book genre (e.g. Science Fiction, French
>>> Poetry etc.)"
>>>
>>> )
>>>
>>> def __str__(self):
>>>
>>> """String for representing the Model object (in Admin site
>>> etc.)"""
>>>
>>> return self.name
>>>
>>> class Book(models.Model):
>>>
>>> """Model representing a book (but not a specific copy of a book)."""
>>>
>>> title = models.CharField(max_length=200)
>>>
>>> author = models.ForeignKey('Author', on_delete=models.SET_NULL,
>>> null=True)
>>>
>>> # Foreign Key used because book can only have one author, but
>>> authors can have multiple books
>>>
>>> # Author as a string rather than object because it hasn't been
>>> declared yet in file.
>>>
>>> summary = models.TextField(
>>>
>>> max_length=1000, help_text="Enter a brief description of the
>>> book")
>>>
>>> isbn = models.CharField('ISBN', max_length=13,
>>>
>>> unique=True,
>>>
>>> help_text='13 Character https://www.isbn-international.org/content/what-isbn'
>>>
>>>   '">ISBN number')
>>>
>>> genre = models.ManyToManyField(
>>>
>>> Genre, help_text="Select a genre for this book")
>>>
>>> # ManyToManyField used because a genre can contain many books and a
>>> Book can cover many genres.
>>>
>>> # Genre class has already been defined so we can specify the object
>>> above.
>>>
>>> language = models.ForeignKey(
>>>
>>> 'Language', on_delete=models.SET_NULL, null=True)
>>>
>>> class Meta:
>>>
>>> ordering = ['title', 'author']
>>>
>>> def display_genre(self):
>>>
>>> """Creates a string for the Genre. This is required to display
>>> genre in Admin."""
>>>
>>> return ', '.join([genre.name for genre in self.genre.all()[:3]])
>>>
>>> display_genre.short_description = 'Genre'
>>>
>>> def get_absolute_url(self):
>>>
>>> """Returns the url to access a particular book instance."""
>>>
>>> return reverse('book

Re: TemplateDoesNotExist at /catalog/books/

2021-10-06 Thread Никита Назаров
Hello!
Thank you!
I'm sorry. How could I do this? 

среда, 6 октября 2021 г. в 11:20:19 UTC+3, adeyem...@gmail.com: 

> Hi, I observed that you didn't specify the template name attribute for the 
> BookListView and BookDetailView, that should solve you problem.
>
> On Tuesday, October 5, 2021 at 10:37:19 PM UTC+2 nazni...@gmail.com wrote:
>
>> Hello!
>> I’m beginner in Django. I do Django Tutorial from Mozilla.
>> I get TemplateDoesNotExist at /catalog/books/ . Could you help me?. I 
>> don’t understand how to resolve it.
>>
>> */catalog/urls*
>>
>> from django.urls import path
>>
>> from . import views
>>
>> urlpatterns = [
>>
>> path('', views.index, name='index'),
>>
>> path('books/', views.BookListView.as_view(), name='books'),
>>
>> path('book/', views.BookDetailView.as_view(), 
>> name='book-detail'),
>>
>> ]
>>
>> *catalog/models*
>>
>> # Used to generate URLs by reversing the URL patterns
>>
>> from django.urls import reverse
>>
>> from django.db import models
>>
>> from django.urls import reverse
>>
>> import uuid
>>
>> # Create your models here
>>
>> class Genre(models.Model):
>>
>> """Model representing a book genre (e.g. Science Fiction, Non 
>> Fiction)."""
>>
>> name = models.CharField(
>>
>> max_length=200,
>>
>> help_text="Enter a book genre (e.g. Science Fiction, French 
>> Poetry etc.)"
>>
>> )
>>
>> def __str__(self):
>>
>> """String for representing the Model object (in Admin site 
>> etc.)"""
>>
>> return self.name
>>
>> class Book(models.Model):
>>
>> """Model representing a book (but not a specific copy of a book)."""
>>
>> title = models.CharField(max_length=200)
>>
>> author = models.ForeignKey('Author', on_delete=models.SET_NULL, 
>> null=True)
>>
>> # Foreign Key used because book can only have one author, but authors 
>> can have multiple books
>>
>> # Author as a string rather than object because it hasn't been 
>> declared yet in file.
>>
>> summary = models.TextField(
>>
>> max_length=1000, help_text="Enter a brief description of the 
>> book")
>>
>> isbn = models.CharField('ISBN', max_length=13,
>>
>> unique=True,
>>
>> help_text='13 Character https://www.isbn-international.org/content/what-isbn'
>>
>>   '">ISBN number')
>>
>> genre = models.ManyToManyField(
>>
>> Genre, help_text="Select a genre for this book")
>>
>> # ManyToManyField used because a genre can contain many books and a 
>> Book can cover many genres.
>>
>> # Genre class has already been defined so we can specify the object 
>> above.
>>
>> language = models.ForeignKey(
>>
>> 'Language', on_delete=models.SET_NULL, null=True)
>>
>> class Meta:
>>
>> ordering = ['title', 'author']
>>
>> def display_genre(self):
>>
>> """Creates a string for the Genre. This is required to display 
>> genre in Admin."""
>>
>> return ', '.join([genre.name for genre in self.genre.all()[:3]])
>>
>> display_genre.short_description = 'Genre'
>>
>> def get_absolute_url(self):
>>
>> """Returns the url to access a particular book instance."""
>>
>> return reverse('book-detail', args=[str(self.id)])
>>
>> def __str__(self):
>>
>> """String for representing the Model object."""
>>
>> return self.title
>>
>> class Language(models.Model):
>>
>> name = models.CharField(
>>
>> max_length=50, help_text="Enter the book's natural language (e.g. 
>> English, French, Japanese etc.)")
>>
>> def __str__(self):
>>
>> return self.name
>>
>> class BookInstance(models.Model):
>>
>> id = models.UUIDField(primar

Re: TemplateDoesNotExist at /catalog/books/

2021-10-06 Thread Adeyemi Deji
Hi, I observed that you didn't specify the template name attribute for the 
BookListView and BookDetailView, that should solve you problem.

On Tuesday, October 5, 2021 at 10:37:19 PM UTC+2 nazni...@gmail.com wrote:

> Hello!
> I’m beginner in Django. I do Django Tutorial from Mozilla.
> I get TemplateDoesNotExist at /catalog/books/ . Could you help me?. I 
> don’t understand how to resolve it.
>
> */catalog/urls*
>
> from django.urls import path
>
> from . import views
>
> urlpatterns = [
>
> path('', views.index, name='index'),
>
> path('books/', views.BookListView.as_view(), name='books'),
>
> path('book/', views.BookDetailView.as_view(), 
> name='book-detail'),
>
> ]
>
> *catalog/models*
>
> # Used to generate URLs by reversing the URL patterns
>
> from django.urls import reverse
>
> from django.db import models
>
> from django.urls import reverse
>
> import uuid
>
> # Create your models here
>
> class Genre(models.Model):
>
> """Model representing a book genre (e.g. Science Fiction, Non 
> Fiction)."""
>
> name = models.CharField(
>
> max_length=200,
>
> help_text="Enter a book genre (e.g. Science Fiction, French Poetry 
> etc.)"
>
> )
>
> def __str__(self):
>
> """String for representing the Model object (in Admin site etc.)"""
>
> return self.name
>
> class Book(models.Model):
>
> """Model representing a book (but not a specific copy of a book)."""
>
> title = models.CharField(max_length=200)
>
> author = models.ForeignKey('Author', on_delete=models.SET_NULL, 
> null=True)
>
> # Foreign Key used because book can only have one author, but authors 
> can have multiple books
>
> # Author as a string rather than object because it hasn't been 
> declared yet in file.
>
> summary = models.TextField(
>
> max_length=1000, help_text="Enter a brief description of the book")
>
> isbn = models.CharField('ISBN', max_length=13,
>
> unique=True,
>
> help_text='13 Character https://www.isbn-international.org/content/what-isbn'
>
>   '">ISBN number')
>
> genre = models.ManyToManyField(
>
> Genre, help_text="Select a genre for this book")
>
> # ManyToManyField used because a genre can contain many books and a 
> Book can cover many genres.
>
> # Genre class has already been defined so we can specify the object 
> above.
>
> language = models.ForeignKey(
>
> 'Language', on_delete=models.SET_NULL, null=True)
>
> class Meta:
>
> ordering = ['title', 'author']
>
> def display_genre(self):
>
> """Creates a string for the Genre. This is required to display 
> genre in Admin."""
>
> return ', '.join([genre.name for genre in self.genre.all()[:3]])
>
> display_genre.short_description = 'Genre'
>
> def get_absolute_url(self):
>
> """Returns the url to access a particular book instance."""
>
> return reverse('book-detail', args=[str(self.id)])
>
> def __str__(self):
>
> """String for representing the Model object."""
>
> return self.title
>
> class Language(models.Model):
>
> name = models.CharField(
>
> max_length=50, help_text="Enter the book's natural language (e.g. 
> English, French, Japanese etc.)")
>
> def __str__(self):
>
> return self.name
>
> class BookInstance(models.Model):
>
> id = models.UUIDField(primary_key=True, default=uuid.uuid4,
>
>   help_text="Unique ID for this particular book 
> across whole library")
>
> book = models.ForeignKey('Book', on_delete=models.SET_NULL, null=True)
>
> imprint = models.CharField(max_length=200)
>
> due_back = models.DateField(null=True, blank=True)
>
> LOAN_STATUS = (
>
> ('m', 'Maintenance'),
>
> ('o', 'On loan'),
>
> ('a', 'Available'),
>
> ('r', 'Reserved'),
>
> )
>
> status = models.CharField(max_length=

TemplateDoesNotExist at /catalog/books/

2021-10-05 Thread Никита Назаров


Hello!
I’m beginner in Django. I do Django Tutorial from Mozilla.
I get TemplateDoesNotExist at /catalog/books/ . Could you help me?. I don’t 
understand how to resolve it.

*/catalog/urls*

from django.urls import path

from . import views

urlpatterns = [

path('', views.index, name='index'),

path('books/', views.BookListView.as_view(), name='books'),

path('book/', views.BookDetailView.as_view(), 
name='book-detail'),

]

*catalog/models*

# Used to generate URLs by reversing the URL patterns

from django.urls import reverse

from django.db import models

from django.urls import reverse

import uuid

# Create your models here

class Genre(models.Model):

"""Model representing a book genre (e.g. Science Fiction, Non 
Fiction)."""

name = models.CharField(

max_length=200,

help_text="Enter a book genre (e.g. Science Fiction, French Poetry 
etc.)"

)

def __str__(self):

"""String for representing the Model object (in Admin site etc.)"""

return self.name

class Book(models.Model):

"""Model representing a book (but not a specific copy of a book)."""

title = models.CharField(max_length=200)

author = models.ForeignKey('Author', on_delete=models.SET_NULL, 
null=True)

# Foreign Key used because book can only have one author, but authors 
can have multiple books

# Author as a string rather than object because it hasn't been declared 
yet in file.

summary = models.TextField(

max_length=1000, help_text="Enter a brief description of the book")

isbn = models.CharField('ISBN', max_length=13,

unique=True,

help_text='13 Character https://www.isbn-international.org/content/what-isbn'

  '">ISBN number')

genre = models.ManyToManyField(

Genre, help_text="Select a genre for this book")

# ManyToManyField used because a genre can contain many books and a 
Book can cover many genres.

# Genre class has already been defined so we can specify the object 
above.

language = models.ForeignKey(

'Language', on_delete=models.SET_NULL, null=True)

class Meta:

ordering = ['title', 'author']

def display_genre(self):

"""Creates a string for the Genre. This is required to display 
genre in Admin."""

return ', '.join([genre.name for genre in self.genre.all()[:3]])

display_genre.short_description = 'Genre'

def get_absolute_url(self):

"""Returns the url to access a particular book instance."""

return reverse('book-detail', args=[str(self.id)])

def __str__(self):

"""String for representing the Model object."""

return self.title

class Language(models.Model):

name = models.CharField(

max_length=50, help_text="Enter the book's natural language (e.g. 
English, French, Japanese etc.)")

def __str__(self):

return self.name

class BookInstance(models.Model):

id = models.UUIDField(primary_key=True, default=uuid.uuid4,

  help_text="Unique ID for this particular book 
across whole library")

book = models.ForeignKey('Book', on_delete=models.SET_NULL, null=True)

imprint = models.CharField(max_length=200)

due_back = models.DateField(null=True, blank=True)

LOAN_STATUS = (

('m', 'Maintenance'),

('o', 'On loan'),

('a', 'Available'),

('r', 'Reserved'),

)

status = models.CharField(max_length=1, choices=LOAN_STATUS,

  blank=True, default='m', help_text='Book 
availability')

class Meta:

ordering = ["due_back"]

def __str__(self):

"""

String for representing the Model object

"""

return '%s (%s)' % (self.id, self.book.title)

class Author(models.Model):

"""

Model representing an author.

"""

first_name = models.CharField(max_length=100)

last_name = models.CharField(max_length=100)

date_of_birth = models.DateField(null=True, blank=True)

date_of_death = models.DateField('Died', null=True, blank=True)


def get_absolute_url(self):

"""

Returns the url to access a particular author instance.

"""

return reverse('author-detail'