[PYTHON] Cannot migrate from direct_to_template to TemplateView

Django Tutorial (Part 2) Reference URL: http://codezine.jp/article/detail/4264?p=3

If you proceed with the above tutorial in Django 1.6 ...

#Abbreviation
from django.views.generic.simple import direct_to_template
#Abbreviation
def item_page_display(request, item_id):
    item = get_object_or_404(Item, id=item_id)
    return direct_to_template(request, 'page/item.html', extra_context = {'item': item })

Then, ImportError of direct_to_template will appear, so Consider using TemplateView. Reference URL: http://stackoverflow.com/questions/11005733/moving-from-direct-to-template-to-new-templateview-in-django

However, AttributeError:'function' object has no attribute'get' happened in process_response in site-packages / django / middleware / clickjacking.py, so I don't know. Import and use render and render_to_response that work similar to direct_to_template.

#Abbreviation
from django.shortcuts import render, render_to_response
from django.template import RequestContext
#Abbreviation
def item_page_display(request, item_id):
    item = get_object_or_404(Item, id=item_id)
    return render_to_response('page/item.html', {'item':item}, context_instance=RequestContext(request))
    #Or, simpler, return render(request, 'page/item.html', {'item': item})

Reference URL: https://groups.google.com/forum/#!topic/django-users/ZuDi-iqd1Xk

Now the product screen is displayed.

shot.png

Recommended Posts

Cannot migrate from direct_to_template to TemplateView
Migrate from requirements.txt to pipenv
Migrate from VS Code to PyCharm
Sum from 1 to 10
[AWS] Migrate data from DynamoDB to Aurora MySQL
Changes from Python 3.0 to Python 3.5
Changes from Python 2 to Python 3.0
Transition from WSL1 to WSL2
From editing to execution
Post from Python to Slack
Cheating from PHP to Python
Porting from argparse to hydra
Migrating from Chainer v1 to Chainer v2
Anaconda updated from 4.2.0 to 4.3.0 (python3.5 updated to python3.6)
Migrated from Flask-RESTPlus to Flask-RESTX
Update python-social-auth from 0.1.x to 0.2.x
Switch from python2.7 to python3.6 (centos7)
Connect to sqlite from python
Migrate Qiita articles to GitHub
Migrate Qiita articles to WordPress