Site icon JnPnote

Following Django Tutorial (Todo App)-Part2

This post is following from the part1.
As I mentioned at last on previous post, I used two different name of project, djangoTodo and test_1. It is because I started the project first and then start writing this blog for record and understand more for myself, so I restarted the test one to do it over again. I will resume to the original project name djangoTodo in middle of this post.

There are some explanation of each files like manage.py, settings.py, urls.py, and etc. on video of the JustDjango Learn. I will not go over those in this post, so please visit their site to watch the video if you need. Also, the orders of this post and their video might be different because I think adding create super user should be comes first.

1. Create Super User

I don’t know why my site is in dark mode. Even I turned off my settings….

2. Creating App

3. Setup the settings for newly created app

4. models.py

class Todo(models.Model):
	name = models.CharField(max_length=100)
	due_date = models.DateField()

5. Migration

6. Show todo on admin

from .models import Todo

admin.site.register(Todo)

7. Return the name as entered

	def __str__(self):
		return self.name

8. Using HttpResponse to show Hello World

from django.http import HttpResponse


def todo_list(request):
	return HttpResponse("Hello World")
from todo.views import todo_list

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', todo_list)
]

9. Using html Templates to show Hello World

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>test</title>
</head>
<body>
	Hello World
</body>
</html>
BASE_DIR / 'templates'
render(request, "todo_list.html")

I stop here because the post is getting too long since I use screenshots a lot.

Exit mobile version