Summary of stumbling blocks in Django for the first time

It's too common sense for people who use it normally.

I got an error when I wrote Japanese in the code

Add the following to the first line of code.

python


# -*- coding: utf-8 -*-

After POST, it became Forbidden

CSRF verification failed. Request aborted.



 Added to settings.py (Django 1.4.1 did not require settings)


#### **`settings.py`**
```python


MIDDLEWARE_CLASSES = (
…
'django.middleware.csrf.CsrfViewMiddleware',
…

Add the following to the template file form

{% csrf_token %}

Modifying the view file (for the code created in the tutorial)

python


from django.template import RequestContext
…
def detail(request, poll_id):
    p = get_object_or_404(Poll, pk=poll_id)
    #return render_to_response('polls/detail.html', {'poll': p})
    return render_to_response('polls/detail.html', {'poll': p}, context_instance=RequestContext(request))
…

reference https://docs.djangoproject.com/en/dev/ref/contrib/csrf/#ref-contrib-csrf

Recommended Posts

Summary of stumbling blocks in Django for the first time
Start Django for the first time
MongoDB for the first time in Python
Summary of stumbling blocks in installing CaboCha
The story of returning to the front line for the first time in 5 years and refactoring Python Django
Kaggle for the first time (kaggle ①)
Kaguru for the first time
Register a task in cron for the first time
[For self-learning] Go2 for the first time
See python for the first time
The meaning of ".object" in Django
I tried tensorflow for the first time
Summary of various for statements in Python
Let's try Linux for the first time
For the first time in Numpy, I will update it from time to time
A useful note when using Python for the first time in a while
How to use MkDocs for the first time
[Note] Deploying Azure Functions for the first time
I tried python programming for the first time.
Read the output of subprocess.Popen in real time
I tried Mind Meld for the first time
The story of viewing media files in Django
Try posting to Qiita for the first time
[IOS] Change the display time for each frame of GIF animation in Pythonista3.
Data analysis in Python Summary of sources to look at first for beginners
Let's display a simple template that is ideal for Django for the first time
Learning notes for the migrations feature in the Django framework (2)
What I got into Python for the first time
A list of stumbling blocks in Django's image upload
I tried Python on Mac for the first time.
I tried python on heroku for the first time
For the first time, I learned about Unix (Linux).
Learning notes for the migrations feature in the Django framework (3)
Check for the existence of BigQuery tables in Java
Learning notes for the migrations feature in the Django framework (1)
Runner-up in the first hackathon of the Zukoke rookie trio!
AI Gaming I tried it for the first time
After attending school, I participated in SIGNATE's BEGINNER limited competition for the first time.
I want to create a lunch database [EP1] Django study for the first time
I want to create a lunch database [EP1-4] Django study for the first time
Check the processing time and the number of calls for each process in python (cProfile)
I participated in the translation activity of Django official documents
The story of creating a "spirit and time chat room" exclusively for engineers in the company
Check the operation of Python for .NET in each environment
Django + MongoDB development environment maintenance (in the middle of writing)
[Updated from time to time] Summary of design patterns in Java
[For beginners] Summary of standard input in Python (with explanation)
[Understand in the shortest time] Python basics for data analysis
Introducing yourself at Qiita for the first time (test post)
Display the time in Django according to the user's region (UTC)
Get the number of occurrences for each element in the list
I tried the Google Cloud Vision API for the first time
Google search for the last line of the file in Python
What kind of environment should people who are learning Python for the first time build?
If you're learning Linux for the first time, do this!
Put the process to sleep for a certain period of time (seconds) or more in Python
The story of releasing a Python text check tool on GitHub x CircleCI for the first time
What I learned by writing a Python Pull Request for the first time in my life
About the need for the first slash in the subscriber name and publisher name
I compared the calculation time of the moving average written in Python
Wrap (part of) the AtCoder Library in Cython for use in Python