128 lines
5.3 KiB
HTML
128 lines
5.3 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>django | Kitaab</title>
|
|
<meta property="og:title" content="django | Kitaab">
|
|
<meta property="og:type" content="website">
|
|
<meta property="og:description"
|
|
content="config.site_meta_description">
|
|
<meta property="og:site_name" content="Kitaab">
|
|
<meta property="og:url" content="build_url">
|
|
<meta property="og:image" content="build_urlassets/social.png">
|
|
<meta property="og:image:height" content="300">
|
|
<meta property="og:image:width" content="300">
|
|
<meta property="og:image:type" content="image/jpeg">
|
|
<link rel="stylesheet" href="asset/style.css" type="text/css"
|
|
media="screen" title="no title" charset="utf-8">
|
|
<!-- Mastodon stuff should go here
|
|
<meta name="twitter:site" content="config.twitter_name">
|
|
<meta name="twitter:title" content="page_title | config.name_of_site">
|
|
<meta name="twitter:image" content="build_urlassets/social.png">
|
|
<meta name="twitter:image:alt" content="page_title | config.name_of_site">
|
|
--!>
|
|
<link rel="apple-touch-icon" sizes="57x57" href="build_urlassets/apple-icon-57x57.png">
|
|
<link rel="apple-touch-icon" sizes="60x60" href="build_urlassets/apple-icon-60x60.png">
|
|
<link rel="apple-touch-icon" sizes="72x72" href="build_urlassets/apple-icon-72x72.png">
|
|
<link rel="apple-touch-icon" sizes="76x76" href="build_urlassets/apple-icon-76x76.png">
|
|
<link rel="apple-touch-icon" sizes="114x114" href="build_urlassets/apple-icon-114x114.png">
|
|
<link rel="apple-touch-icon" sizes="120x120" href="build_urlassets/apple-icon-120x120.png">
|
|
<link rel="apple-touch-icon" sizes="144x144" href="build_urlassets/apple-icon-144x144.png">
|
|
<link rel="apple-touch-icon" sizes="152x152" href="build_urlassets/apple-icon-152x152.png">
|
|
<link rel="apple-touch-icon" sizes="180x180" href="build_urlassets/apple-icon-180x180.png">
|
|
<link rel="icon" type="image/png" sizes="192x192" href="build_urlassets/android-icon-192x192.png">
|
|
<link rel="icon" type="image/png" sizes="32x32" href="build_urlassets/favicon-32x32.png">
|
|
<link rel="icon" type="image/png" sizes="96x96" href="build_urlassets/favicon-96x96.png">
|
|
<link rel="icon" type="image/png" sizes="16x16" href="build_urlassets/favicon-16x16.png">
|
|
<meta name="msapplication-TileColor" content="#5927e0">
|
|
<meta name="msapplication-TileImage" content="build_urlassets/ms-icon-144x144.png">
|
|
<meta name="theme-color" content="#5927e0">
|
|
<link rel="canonical" href="Raw">
|
|
<link rel="stylesheet" href="assets/main.css">
|
|
</head>
|
|
|
|
<body class="flow-large container">
|
|
<header>
|
|
<a style='display:flex;padding-top:10px' href="home.html" aria-label="Kitaab">Kitaab</a>
|
|
</header>
|
|
<main>
|
|
<div id='navigation' style="float: right;">
|
|
<nav>
|
|
<h2> <a href='tag_index.html'> Index </a> </h2>
|
|
<ul>
|
|
<li> <a href='recents.html'>recents</a></li>
|
|
|
|
<li> <a href='dev_index.html'>dev</a></li>
|
|
|
|
<li> <a href='way_index.html'>way</a></li>
|
|
|
|
<li> <a href='recipe_index.html'>recipe</a></li>
|
|
|
|
<li> <a href='ops_index.html'>ops</a></li>
|
|
|
|
<li> <a href='blog_index.html'>blog</a></li>
|
|
|
|
<li> <a href='rock_index.html'>rock</a></li>
|
|
|
|
<li> <a href='phil_index.html'>phil</a></li>
|
|
|
|
<li> <a href='story_index.html'>story</a></li>
|
|
|
|
<li> <a href='blog_index.html'>blog</a></li>
|
|
|
|
<li> <a href='untagged_index.html'>untagged</a></li>
|
|
|
|
</ul>
|
|
</nav>
|
|
</div>
|
|
<h1> django </h1>
|
|
<div style='max-width:660px;'>
|
|
<article class="flow">
|
|
|
|
|
|
<date>1970-01-01 10:00</date>
|
|
|
|
<h3>basics</h3>
|
|
<p>django-admin.py is stored in .local/lib/python3.7/django/bin</p>
|
|
<p>create a project:
|
|
django-admin.py startproject mysite</p>
|
|
<p>start server:
|
|
python3 manage.py runserver</p>
|
|
<p>create app within a project:
|
|
python3 manage.py startapp appname</p>
|
|
<p>migrate the model:
|
|
python3 manage.py migrate</p>
|
|
<p>add myapp migrations:
|
|
add 'myapp.apps.myappConfig' to mysite/settings.py
|
|
python3 manage.py makemigrations myapp
|
|
python3 manage.py migrate</p>
|
|
<p>view migration 0001:
|
|
python manage.py sqlmigrate myapp 0001</p>
|
|
<p>launch interactive shell:
|
|
python manage.py shell</p>
|
|
<h3>views</h3>
|
|
<p>to add a view, we must first have a route
|
|
routes are defined in urls.py files and are defined with
|
|
django.urls.path() in the urlpatterns list</p>
|
|
<p>for an app subcomponent to the view, urls.py in the main site must provide a route to the app urls.py</p>
|
|
<p>each view should have an associated function in the urls path. this function takes a template and applies the necessary transformations by adding the specific data to that template. we do this by defining the context in the .py file and then adding the code to the .html file with {% <code> %}</p>
|
|
<h3>models</h3>
|
|
<p>on creating a project we must migrate to create the database</p>
|
|
<p>models are created of fields, and each database is a class that extends the models.Model class from django.db</p>
|
|
<p>there are many sorts of Fields (as well as other variables within a model)</p>
|
|
<h3>shell</h3>
|
|
<p>django has a rich api for querying models, these are only examples:</p>
|
|
<p>get all entries:</p>
|
|
<p><Model name>.objects.all()</p>
|
|
<p>get the first entry:</p>
|
|
<p><Mn>.objects.filter(id=1)</p>
|
|
<p><Mn>.objects.get(pk=1)</p>
|
|
|
|
</article>
|
|
</div>
|
|
</main>
|
|
</body>
|
|
|
|
</html> |