diff --git a/README.md b/README.md index dd6f068..3d24470 100644 --- a/README.md +++ b/README.md @@ -20,4 +20,4 @@ Current tutorials are: ## Contributing These tutorials are maintained by [DjangoGirls](http://djangogirls.org/). If you find any mistakes or want to update the tutorial -please [follow the contributing guidelines](https://github.com/DjangoGirls/tutorial-extension/contributing/). +please [follow the contributing guidelines](./contributing/README.md). diff --git a/en/homework/README.md b/en/homework/README.md index 01a0132..894adf6 100644 --- a/en/homework/README.md +++ b/en/homework/README.md @@ -21,7 +21,7 @@ Time to do something similar, but for draft posts. Let's add a link in `blog/templates/blog/base.html` in the header. We don't want to show our list of drafts to everybody, so we'll put it inside the {% raw %}`{% if user.is_authenticated %}`{% endraw %} check, right after the button for adding new posts. ```django - +Drafts ``` Next: urls! In `blog/urls.py` we add: @@ -84,8 +84,8 @@ into these: {{ post.published_date }} {% else %} -
{% csrf_token %} - + {% csrf_token %} +
{% endif %} ``` @@ -101,7 +101,7 @@ Now, let's take a look at the details of the form. We are using a new attribute, Time to create a URL (in `blog/urls.py`): ```python -path('post//publish/', views.post_publish, name='post_publish'), +path('post//publish/', views.post_publish, name='post_publish'), ``` and finally, a *view* (as always, in `blog/views.py`): @@ -137,9 +137,9 @@ Congratulations! You are almost there. The last step is adding a delete button! Let's open `blog/templates/blog/post_detail.html` once again and add these lines: ```django -
{% csrf_token %} +{% csrf_token %}
``` @@ -149,7 +149,7 @@ just under a line with the edit button. Now we need a URL (`blog/urls.py`): ```python -path('post//remove/', views.post_remove, name='post_remove'), +path('post//remove/', views.post_remove, name='post_remove'), ``` Now, time for a view! Open `blog/views.py` and add this code: diff --git a/es/homework/README.md b/es/homework/README.md index b07ee80..7725bcf 100644 --- a/es/homework/README.md +++ b/es/homework/README.md @@ -21,7 +21,7 @@ Es tiempo de hacer algo similiar, pero con borradores. Vamos a añadir un enlace en `blog/templates/blog/base.html` en el encabezado. No queremos mostrar nuestro borradores a todo el mundo, entonces vamos a colocarlo dentro de la verificación {% raw %}`{% if user.is_authenticated %}`{% endraw %}, justo después del botón de agregar posts. ```django - +Drafts ``` Siguiente: ¡urls! en `blog/urls.py` vamos a agregar: @@ -84,7 +84,9 @@ por estas: {{ post.published_date }} {% else %} - Publish +
{% csrf_token %} + +
{% endif %} ``` @@ -93,7 +95,7 @@ Como puedes ver, hemos agregado la línea {% raw %}`{% else %}`{% endraw %}. Est Tiempo de crear una URL (en `blog/urls.py`): ```python -path('post//publish/', views.post_publish, name='post_publish'), +path('post//publish/', views.post_publish, name='post_publish'), ``` Y finalmente una *vista* (como siempre, en `blog/views.py`): @@ -101,7 +103,8 @@ Y finalmente una *vista* (como siempre, en `blog/views.py`): ```python def post_publish(request, pk): post = get_object_or_404(Post, pk=pk) - post.publish() + if request.method=='POST': + post.publish() return redirect('post_detail', pk=pk) ``` @@ -126,7 +129,11 @@ Y de nuevo al publicar el post, ¡somos redirigidos inmediatamente a la página Vamos a abrir `blog/templates/blog/post_detail.html` de nuevo y vamos a añadir esta línea ```django - +
{% csrf_token %} + +
``` Justo debajo de la línea co el botón editar. @@ -134,7 +141,7 @@ Justo debajo de la línea co el botón editar. Ahora necesitamos una URL (`blog/urls.py`): ```python -path('post//remove/', views.post_remove, name='post_remove'), +path('post//remove/', views.post_remove, name='post_remove'), ``` Ahora, ¡Tiempo para la vista! Abre `blog/views.py` y agrega este código: @@ -142,7 +149,8 @@ Ahora, ¡Tiempo para la vista! Abre `blog/views.py` y agrega este código: ```python def post_remove(request, pk): post = get_object_or_404(Post, pk=pk) - post.delete() + if request.method=='POST': + post.delete() return redirect('post_list') ``` diff --git a/fa/homework/README.md b/fa/homework/README.md index fca3438..14a877b 100644 --- a/fa/homework/README.md +++ b/fa/homework/README.md @@ -21,7 +21,7 @@ post.published_date = timezone.now() حالا می‌خواهیم در هدر فایل `blog/templates/blog/base.html` یک لینک اضافه کنیم. از آنجا که نمی‌خواهیم لیست پست‌های پیش‌نویس را به همه نشان بدهیم، پس این لینک رادر عبارت کنترلی {% raw %}`{% if user.is_authenticated %}`{% endraw %} و دقیقاً بعد از دکمه مربوط به اضافه کردن پست جدید، اضافه می‌کنیم. ```django - +Drafts ``` حالا وقت اصلاح urlها در فایل `blog/urls.py` است: @@ -84,7 +84,9 @@ def post_draft_list(request): {{ post.published_date }} {% else %} - Publish +
{% csrf_token %} + +
{% endif %} ``` @@ -93,7 +95,7 @@ def post_draft_list(request): زمان ساختن یک URL (در فایل `blog/urls.py`) است: ```python -path('post//publish/', views.post_publish, name='post_publish'), +path('post//publish/', views.post_publish, name='post_publish'), ``` و در نهایت یک *ویو* (مانند همیشه در فایل `blog/views.py`) می‌سازیم: @@ -101,7 +103,8 @@ path('post//publish/', views.post_publish, name='post_publish'), ```python def post_publish(request, pk): post = get_object_or_404(Post, pk=pk) - post.publish() + if request.method=='POST': + post.publish() return redirect('post_detail', pk=pk) ``` @@ -115,7 +118,7 @@ def publish(self): حالا بالاخره می‌توانیم از آن استفاده کنیم! -و یک بار دیگر بعد از انتشار پست ما بلافاصله به صفحه جزییات پست یا `post_detail` هدایت خواهیم شد! +و یک بار دیگر بعد از انتشار پست ما بلافاصله به صفحه جزییات پست یا `post_detail` هدایت خواهیم شد! ![Publish button](images/publish2.png) @@ -126,7 +129,11 @@ def publish(self): بیایید یک بار دیگر فایل `blog/templates/blog/post_detail.html` را باز کنید و این خط را به آن اضافه کنید: ```django - +
{% csrf_token %} + +
``` دقیقاً زیر خطی که دکمه اصلاح یا Edit button قرار دارد. @@ -134,7 +141,7 @@ def publish(self): حالا یک URL لازم داریم (`blog/urls.py`): ```python -path('post//remove/', views.post_remove, name='post_remove'), +path('post//remove/', views.post_remove, name='post_remove'), ``` و الان زمان اضافه کردن یک ویو است! فایل `blog/views.py` را باز کنید و این کد را به آن اضافه کنید: @@ -142,7 +149,8 @@ path('post//remove/', views.post_remove, name='post_remove'), ```python def post_remove(request, pk): post = get_object_or_404(Post, pk=pk) - post.delete() + if request.method=='POST': + post.delete() return redirect('post_list') ``` diff --git a/ja/homework/README.md b/ja/homework/README.md index 8312a79..9189136 100644 --- a/ja/homework/README.md +++ b/ja/homework/README.md @@ -21,7 +21,7 @@ Djangoのクエリセットを勉強した章を覚えていますか? `post_lis `blog/templates/blog/base.html` のヘッダーにリンクを追加しましょう。草稿の一覧は誰でも見られるようにはしません。なので、 {% raw %}`{% if user.is_authenticated %}`{% endraw %} という条件の確認に続く箇所で、新しい投稿を追加するボタンのすぐ後にリンクを書いてください。 ```django - +Drafts ``` 次は `blog/urls.py` に、urlを追加しましょう! @@ -84,7 +84,9 @@ def post_draft_list(request): {{ post.published_date }} {% else %} - Publish +
{% csrf_token %} + +
{% endif %} ``` @@ -93,7 +95,7 @@ def post_draft_list(request): それでは新しいURLを追加しましょう。( `blog/urls.py` に) ```python -path('post//publish/', views.post_publish, name='post_publish'), +path('post//publish/', views.post_publish, name='post_publish'), ``` 最後に *ビュー* を追加します。(いつものように `blog/views.py` に) @@ -101,7 +103,8 @@ path('post//publish/', views.post_publish, name='post_publish'), ```python def post_publish(request, pk): post = get_object_or_404(Post, pk=pk) - post.publish() + if request.method=='POST': + post.publish() return redirect('post_detail', pk=pk) ``` @@ -127,13 +130,17 @@ def publish(self): 下の行を編集ボタンの行の直後に追加します: ```django - +
{% csrf_token %} + +
``` URLも必要ですね。( `blog/urls.py` に) ```python -path('post//remove/', views.post_remove, name='post_remove'), +path('post//remove/', views.post_remove, name='post_remove'), ``` 次はビューも作りましょう。 `blog/views.py` を開いて下のコードを追加してください。 @@ -141,7 +148,8 @@ path('post//remove/', views.post_remove, name='post_remove'), ```python def post_remove(request, pk): post = get_object_or_404(Post, pk=pk) - post.delete() + if request.method=='POST': + post.delete() return redirect('post_list') ``` diff --git a/ko/homework/README.md b/ko/homework/README.md index 307022a..b5fabd7 100644 --- a/ko/homework/README.md +++ b/ko/homework/README.md @@ -22,13 +22,13 @@ post.published_date = timezone.now() 새 글 추가하기 버튼 근처에 `blog/templates/blog/base.html` 링크를 추가하세요({% raw %}`

Django Girls Blog

`{% endraw %}위에 바로 추가하면 됩니다!). 발행 전 미리 보기가 모두에게 보이는 걸 원치 않을 거예요. 새로운 글 추가하기 바로 아래에 {% raw %}`{% if user.is_authenticated %}`{% endraw %}을 추가해 주세요. ```django - +Drafts ``` 다음: url입니다! `blog/urls.py`을 열고 아래 내용을 추가할 거에요. ```python -url(r'^drafts/$', views.post_draft_list, name='post_draft_list'), +path('drafts/', views.post_draft_list, name='post_draft_list'), ``` `blog/views.py`에 view를 생성할 차례입니다. @@ -59,7 +59,7 @@ def post_draft_list(request): `post_list.html` 템플릿과 코드가 많이 비슷해보이죠? -브라우저로 `http://127.0.0.1:8000/draft/` 페이지를 열어보면, 미 게시된 글목록을 확인할 수 있어요. +브라우저로 `http://127.0.0.1:8000/drafts/` 페이지를 열어보면, 미 게시된 글목록을 확인할 수 있어요. 야호! 첫 번째 일이 마쳤어요! @@ -85,7 +85,9 @@ def post_draft_list(request): {{ post.published_date }} {% else %} - Publish +
{% csrf_token %} + +
{% endif %} ``` @@ -94,7 +96,7 @@ def post_draft_list(request): `blog/urls.py`에 URL 패턴을 추가해봅시다. ```python -url(r'^post/(?P\d+)/publish/$', views.post_publish, name='post_publish'), +path('post//publish/', views.post_publish, name='post_publish'), ``` 마지막으로 `post_publish` *뷰*를 `blog/views.py` 에 추가해봅시다. @@ -102,7 +104,8 @@ url(r'^post/(?P\d+)/publish/$', views.post_publish, name='post_publish'), ```python def post_publish(request, pk): post = get_object_or_404(Post, pk=pk) - post.publish() + if request.method=='POST': + post.publish() return redirect('post_detail', pk=pk) ``` @@ -127,7 +130,11 @@ def publish(self): `blog/templates/blog/post_detail.html` 파일에 아래 코드를 추가해주세요. ```django - +
{% csrf_token %} + +
``` 수정 버튼 바로 아래 줄에 추가해주세요. @@ -135,7 +142,7 @@ def publish(self): (`blog/urls.py`)에 URL 패턴을 추가해봅시다: ```python -url(r'^post/(?P\d+)/remove/$', views.post_remove, name='post_remove'), +path('post//remove/', views.post_remove, name='post_remove'), ``` 이제 post_remove 뷰를 구현해봅시다. `blog/views.py` 에 아래 코드를 추가해주세요. @@ -143,7 +150,8 @@ url(r'^post/(?P\d+)/remove/$', views.post_remove, name='post_remove'), ```python def post_remove(request, pk): post = get_object_or_404(Post, pk=pk) - post.delete() + if request.method=='POST': + post.delete() return redirect('post_list') ```