Python Django
-
Python Ajax 예제(db 연동)Python Django 2022. 10. 23. 15:55
cmd에서 명령어 입력 후, 원래 있던 테이블을 가져와서 models.py에 붙여놓기 한다. models.py from django.db import models # Create your models here. class Sangdata(models.Model): code = models.IntegerField(primary_key=True) sang = models.CharField(max_length=20, blank=True, null=True) su = models.IntegerField(blank=True, null=True) dan = models.IntegerField(blank=True, null=True) class Meta: managed = False db_table = 'sangda..
-
Python Django 18 - Python AjaxPython Django 2022. 10. 23. 15:43
urls.py from django.contrib import admin from django.urls import path from myapp import views urlpatterns = [ path("admin/", admin.site.urls), path("", views.indexFunc), path("startajax", views.Func1), path("goajax", views.Func2), ] views.py from django.shortcuts import render import time import json from django.http.response import HttpResponse # Create your views here. lan = { 'id' : 123, 'nam..
-
예제(table 가져와서 join해서 결과 나타내기)Python Django 2022. 10. 23. 15:33
urls.py from django.contrib import admin from django.urls import path from myapp import views urlpatterns = [ path("admin/", admin.site.urls), path("", views.main), path("show", views.show), ] Function views 방법을 사용하였다. models.py from django.db import models # Create your models here. class Gogek(models.Model): gogek_no = models.IntegerField(primary_key=True) gogek_name = models.CharField(max_len..
-
게시판 예제 - 댓글Python Django 2022. 10. 23. 15:20
veiws2.py from django.shortcuts import render, redirect from myboard.models import BoardTab from datetime import datetime # Create your views here. def replyFunc(request): try: data=BoardTab.objects.get(id=request.GET.get('id')) context={'data_one':data} return render(request, 'rep/reply.html',context) except Exception as e: print('replyFunc err : ', e) return render(request, 'error.html') def r..
-
게시판 예제Python Django 2022. 10. 23. 15:17
settings.py INSTALLED_APPS = [ "django.contrib.admin", "django.contrib.auth", "django.contrib.contenttypes", "django.contrib.sessions", "django.contrib.messages", "django.contrib.staticfiles", "myboard", ] DATABASES = { #리모트(원격) 디비를 걸어놓았다 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'boarddb', # ORM에서는 __contains=값 if s_type == 'title': datas_search = BoardTab.objects.filter(title_..
-
Python Django 17 - table이 존재하는 상황(table 가져오기)Python Django 2022. 10. 23. 15:06
cmd에 들어와서 프로젝트 경로를 입력 후 python manage.py inspectdb > abc.py(파일명 아무거나) 를 적으면 abc.py 파일이 생기면서 table이 담긴다. 해당 table 코드를 models.py에 붙여놓기 하면 된다. models.py from django.db import models # Create your models here. class Sangdata(models.Model): code = models.IntegerField(primary_key=True) sang = models.CharField(max_length=20, blank=True, null=True) su = models.IntegerField(blank=True, null=True) dan = m..
-
Python Django 16 - join 복수의 DB 사용(ORM)Python Django 2022. 10. 23. 15:01
models.py from django.db import models # Create your models here. class Maker(models.Model): mname = models.CharField(max_length=10) tel = models.CharField(max_length=30) addr = models.CharField(max_length=50) class Meta: ordering = ('-id',) def __str__(self): return self.mname class Product(models.Model): pname = models.CharField(max_length=10) price = models.IntegerField() maker_name = models...
-
미니방명록 예제Python Django 2022. 10. 23. 14:55
메인 urls.py from django.contrib import admin from django.urls import path from myguest import views from django.urls.conf import include urlpatterns = [ path("admin/", admin.site.urls), path('', views.MainFunc), path('guest/', include('')) ] include를 사용하여 guest/로 시작되는 것은 자식 urls.py를 생성하여 맡긴다. 자식 urls.py from django.urls import path from myguest import views urlpatterns = [ path('select', views.Li..