# articles > urls.py
더보기
from django.urls import path
from . import views
app_name = 'articles'
urlpatterns = [
path('', views.index, name='index'),
path('<int:pk>/', views.detail, name='detail'),
# path('new/', views.new, name='new'),
path('create/', views.create, name='create'),
path('<int:pk>/delete/', views.delete, name='delete'),
path('<int:pk>/edit/', views.edit, name='edit'),
path('<int:pk>/update/', views.update, name='update'),
]
# articles > templates > articles > index.html
"articles:new" 를 "articles:create"로 바꾸기
더보기
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Articles</h1>
<a href="{% url "articles:create" %}">CREATE</a>
<hr>
{% for article in articles %}
<p>글 번호: {{ article.pk }}</p>
<a href="{% url "articles:detail" article.pk %}">
<p>글 제목: {{ article.title }}</p>
</a>
<p>글 내용: {{ article.content }}</p>
<hr>
{% endfor %}
</body>
</html>
# articles > templates > articles > new.html
new.html 파일의 이름을 create.html로 바꾸기
더보기
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>New</h1>
<form action="{% url "articles:create" %}" method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="submit">
</form>
<hr>
<a href="{% url "articles:index" %}">[back]</a>
</body>
</html>
new 파일의 이름을 create로 바꿔준다
# articles > views.py
여기 확인하기 !
'WEB > Django prac' 카테고리의 다른 글
[Django prac][Form] 12. Widget 응용 (0) | 2024.03.29 |
---|---|
[Django prac][Form] 11. update (0) | 2024.03.29 |
[Django prac][Form] 9. Update , Edit 함수의 의미 (0) | 2024.03.28 |
[Django prac][Form] 8. Handling HTTP requests (0) | 2024.03.28 |
[Django prac][Form] 7. 유효성 검사 (0) | 2024.03.28 |