Site icon JnPnote

Following Django Tutorial (CRM)-Part3

This post is for myself to remember how to build Django project.
I did follow the tutorial from the JustDjango Learn website free tutorial.
And this is the fourth tutorial named Getting Started With Django.
I am not going over all the details and descriptions for each part. There are good explanations on video of the JustDjango Learn. So, visit their site and try their tutorials if you need more details. Also, the orders of this post and their video might be different because I put things first what I think should come first.

I am doing this on Windows 10 with just Windows PowerShell. Not using virtual machines at all.

1. Create super user

python manage.py createsuperuser

2. Add models to admin page

from .models import Agent, Lead, User


admin.site.register(Agent)
admin.site.register(Lead)
admin.site.register(User)

3. Views and Urls(“Hello World”)

from django.http import HttpResponse


def home_page(request):
	return HttpResponse("Hello world")
from leads.views import home_page

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

4. Templates

<!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>
	<h1>Hello World</h1>
</body>
</html>
BASE_DIR / 'templates'
render(request, "home_page.html")

5. Context

from .models import Lead


def home_page(request):
	leads = Lead.objects.all()
	context = {
		"leads": leads
	}
	return render(request, "home_page.html", context)
	<ul>
		{% for lead in leads %}
		<li>{{ lead }}</li>
		{% endfor %}
	</ul>

6. Restructure Urls

from django.urls import path
from .views import home_page


app_name = "leads"

urlpatterns = [
	path('all/', home_page)
]

Done for this post.

Exit mobile version