Django HTML CSS Cheatsheet
Django HTML CSS Cheatsheet
Django Basics
1. Create Project: django-admin startproject projectname
2. Create App: python manage.py startapp appname
3. Run Server: python manage.py runserver
4. Migrations:
- Make: python manage.py makemigrations
- Apply: python manage.py migrate
5. Admin:
- Create superuser: python manage.py createsuperuser
- Register model in admin.py
6. Views:
- Defined in views.py
- Return HttpResponse or render(template.html, context)
7. URLs:
- In project urls.py: path('app/', include('app.urls'))
- In app urls.py: path('route/', view_function, name='name')
8. Templates:
- Use {% %} for logic and {{ }} for variables
- Extend base templates using {% extends "base.html" %}
HTML Basics
1. Structure:
<!DOCTYPE html>
<html>
<head><title>Title</title></head>
<body>Content here</body>
</html>
2. Common Tags:
- <h1> to <h6>: Headings
- <p>: Paragraphs
- <a href="url">Link</a>
- <img src="img.jpg" alt="desc">
- <div>: Container
- <form>: User input
3. Attributes: class, id, href, src, alt, style, etc.
CSS Basics
1. Syntax:
selector { property: value; }
2. Types:
- Inline: <p style="color:red;">
- Internal: <style>...</style> in <head>
- External: link to .css file
3. Selectors:
- .class, #id, tag
- div p (descendant), div > p (child)
4. Box Model: margin, border, padding, content
Django, HTML, CSS Cheatsheet with Explanations
5. Layout:
- display: block, inline, flex, grid
- position: static, relative, absolute, fixed
6. Responsive:
- media queries: @media (max-width: 600px) { ... }