unknown 2 달 전
부모
커밋
acfb64f336
4개의 변경된 파일55개의 추가작업 그리고 25개의 파일을 삭제
  1. 15 7
      courses/django_kind/sitewomen/women/templates/women/index.html
  2. 20 11
      courses/django_kind/sitewomen/women/views.py
  3. BIN
      courses/sqlite/saper.db
  4. 20 7
      courses/sqlite/test_1.py

+ 15 - 7
courses/django_kind/sitewomen/women/templates/women/index.html

@@ -5,12 +5,20 @@
 </head>
 <body>
 <p>{{ menu|join:" | " }}</p>
-<p>{{ float|divisibleby:"2"}}</p>
-<p>{{ lst|length }}</p>
-<p>{{ set }}</p>
-<p>{{ dict.key_1 }} {{ dict.key2 }}</p>
-<p>{{ obj.a }}</p>
-<p>{{ url }}</p>
-<h1>{{ title|cut:" " }}</h1>
+<h1>{{ title }}</h1>
+
+<ul>
+    {% for p in posts %}
+    {% if p.is_published %}
+    <li>
+        <h2>{{ p.title }}</h2>
+        <p>{{ p.content }}</p>
+        {% if not forloop.last %}
+        <hr>
+        {% endif %}
+    </li>
+    {% endfor %}
+</ul>
+
 </body>
 </html>

+ 20 - 11
courses/django_kind/sitewomen/women/views.py

@@ -9,26 +9,35 @@ from django.template.defaultfilters import slugify
 
 menu = ["О сайте", "Добавить сатью", "Обратная связь", "Войти"]
 
-class MyClass:
-    def __init__(self, a, b):
-        self.a = a
-        self.b = b
+
+data_db = [
+    {'id': 1, 'title': 'Анджелина Джоли', 'content': 'Биография Анджелины Джоли', 'is_published': True },
+    {'id': 2, 'title': 'Марго Робби', 'content': 'Биография Марго Робби', 'is_published': False },
+    {'id': 3, 'title': 'Джулия Робертс', 'content': 'Биография Джулия Робертс', 'is_published': True },
+]
 
 
 
 def index(request): # HttRequest
     # t = render_to_string('women/index.html')
     # return HttpResponse(t)
-    data = {'title': 'главная страница?',
+
+    # data = {'title': 'главная страница?',
+    #         'menu': menu,
+    #         'float': 234.465,
+    #         'lst': [1, 2, 'abc', True],
+    #         'set': {1, 2, 3, 4, 5},
+    #         'dict': {'key_1': 'value_1', 'key_2': 'value_2'},
+    #         'obj': MyClass(10, 20),
+    #         'url': slugify("The main page"),
+    # }
+
+    data = {'title': 'Главная страница',
             'menu': menu,
-            'float': 234.465,
-            'lst': [1, 2, 'abc', True],
-            'set': {1, 2, 3, 4, 5},
-            'dict': {'key_1': 'value_1', 'key_2': 'value_2'},
-            'obj': MyClass(10, 20),
-            'url': slugify("The main page"),
+            'posts': data_db,
     }
     
+
     return render(request, 'women/index.html', context=data)
 
 

BIN
courses/sqlite/saper.db


+ 20 - 7
courses/sqlite/test_1.py

@@ -6,20 +6,33 @@ def test_1():
     with sq.connect("saper.db") as con:
         cur = con.cursor() # Cursor
         
-        cur.execute("""DROP TABLE users""") # Удалить тиблицу
+        # cur.execute("DROP TABLE IF EXISTS users")
 
-        con.close()
-
-'''
         cur.execute("""CREATE TABLE IF NOT EXISTS users (
-                    name TEXT,  
-                    sex INTEGER,
+                    user_id INTEGER PRIMARY KEY AUTOINCREMENT,
+                    name TEXT NOT NULL,  
+                    sex INTEGER NOT NULL DEFAULT 1,
                     old INTEGER,
                     score INTEGER
                     )""")
-'''
 
 
+        cur.execute("SELECT * FROM users WHERE score > 100 ORDER BY score DESC LIMIT 5")
+        
+        # result = cur.fetchall() # для получения результата запроса (будет список кортежей)
+        
+        # Для экономии памяти (не формируется весь список записей)
+        for result in cur:
+            print(result)
+
+        # result_2 = cur.fetchone() # получить одну запись
+
+        # result_3 = cur.fetchmany(3) # получить N записей
+
+
+
+        # con.close()
+
 
 def main():
     test_1()