Django, HTML, CSS Cheatsheet with Explanations
Django Basics
1. Create Project: django-admin startproject projectname
2. Create App: python [Link] startapp appname
3. Run Server: python [Link] runserver
4. Migrations:
- Make: python [Link] makemigrations
- Apply: python [Link] migrate
5. Admin:
- Create superuser: python [Link] createsuperuser
- Register model in [Link]
6. Views:
- Defined in [Link]
- Return HttpResponse or render([Link], context)
7. URLs:
- In project [Link]: path('app/', include('[Link]'))
- In app [Link]: path('route/', view_function, name='name')
8. Templates:
- Use {% %} for logic and {{ }} for variables
- Extend base templates using {% extends "[Link]" %}
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="[Link]" 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) { ... }