Category: Python/Django

[Django Recipe] 디자인 부담을 덜어주는 django-adminlte3 part-2

웹 디자인 부담을 덜어주는 django-adminlte3 part-2 base.html 살펴보기. base.html 아래 링크를 참고하여 템플릿에서 사용할 수 있는 블럭의 이름을 알 수 있다. https://github.com/d-demirci/django-adminlte3/blob/master/adminlte3/templates/adminlte/base.html 먼저, 간단히 사이트 이름과 페이지 제목을 변경하고 싶다면, block title_outer를 설정한다. project/templates/index.html 에 title을 설정하면 index.html을 상속받는 모든 페이지에 적용되며, test.html에 설정하면 test.html을 사용하는 페이지에만 적용된다. index.html에 적용하는 경우 {% extends ‘adminlte/base.html’ %} …

Continue reading

[Django Recipe] 웹 디자인 부담을 덜어주는 django-adminlte3 – part 1

웹 디자인 부담을 덜어주는 django-adminlte3 – 1부 adminlte는 다양한 기능을 제공하는 웹템플릿으로 많은 개발자들이 사용한다. 다양한 기능을 편리하게 사용할 수있는 장점이 있으나, 많은 개발자들이 사용하므로 디자인이 비슷하다는 단점이 있다. adminlte는 현재 버전3 까지 나와 있다. * 작업환경 python: 3.6 django: 3.0 os: windows 10 1. 설치 및 설정 설치 pip install django-adminlte3 설정 django project …

Continue reading

web dns query

커맨드라인에서 nslookup 이나 dig를 이용해 dns 쿼리를 가끔 이용하는데, pc를 이용할 수 없는 상황이 생김. 그래서, iPhone web 브라우저에서 dns 쿼리를 가능하게 하도록 프로그램 작성함.(https://webdns.boxcorea.com)

Continue reading

ubuntu 18.04 LTS, Django2 mysqlclient 설치 오류

ubuntu 18.04 LTS 최초 설치후, django mysqlclient 설치 오류 ubuntu 18.04 설치하고, python3, django2, mysql 로 어플리케이션을 배포 환경을 구성. 1. 먼저, Django 어플리케이션 배포를 위해 웹서버와 mod_wsgi를 설치한다. $ sudo apt-get install python3-pip apache2 libapache2-mod-wsgi-py3 2. 어플리케이션이 mysql을 사용하므로, mysql을 설치한다. $ sudo apt-get install mysql-server, mysql-client 3. 배포환경(virtualenv)을 위한 virtualenv를 설치한다. $ sudo …

Continue reading

Django2, settings.py에 설정한 변수를 APP에서 사용하는 방법

settings.py에 설정한 변수를 APP에서 사용하는 방법 Django 프로그램을 작성하다보면 특정 변수를 모든 app 에서 사용하면 좋은 경우가 생긴다. 이런 경우에, settings.py에 변수를 설정하면 원하는 곳에서 불러서 사용할 수 있다. 먼저, settings.py 에 사용하고자 하는 변수(GATHER_INTERVAL)를 넣는다. settings.py … GATHER_INTERVAL = 60 이제, 변수를 사용할 앱에서 아래와 같이 사용하면 된다. getattr() 이 개체의 속성값을 확인하는 함수이므로, …

Continue reading

Django url warning – / 제거?

django2.2 에서, 하나의 프로젝트에 여러개의 app을 들어서 app을 실행했을때 아래와같은 경고가 발생하는 경우, WARNINGS: ?: (urls.W002) Your URL pattern ‘/catsel/’ [name=’select’] has a route beginning with a ‘/’. Remove this slash as it is unnecessary. If this pattern is targeted in an include(), ensure the include() pattern has a trailing ‘/’. System check identified 1 …

Continue reading

[django 2.2] Get/Post를 동일한 템플릿에 표시하기.

Django class based view를 이용하여 동일한 페이지에 GET 과 POST를 모두 표시하는 방법. 1. View 작성(app/views.py) class GetPostView(View): template_name = ‘getpost.html’ data = [ {‘name’: ‘fox’, ‘title’: ‘test1’, ‘is_published’: True }, {‘name’: ‘wolf’, ‘title’: ‘test 2’, ‘is_published’: False}, {‘name’: ‘cat’, ‘title’: ‘life of cat’, ‘is_published’: True}, ] def get(self, request, *argc, **kwargs): context = { …

Continue reading

django2.2 url , url을 text로 유지하는 방법.

django 프로그램을 작성하다 보면, url에 내가원하는 텍스트를 붙여야 하는 경우가 생긴다. url은 주로 http://some.thing/view/123 이나 http://some.thing/view/wanted_text 이런 형식이 될 것이다. models.py가 아래와 같을때, from django.db import models # Create your models here. class TestData(models.Model): ip = models.GenericIPAddressField() mac = models.CharField(max_length=12, default=’000000000000′) date = models.DateTimeField(null=True) explane = models.CharField(max_length=64, null=True) 세 개의 view를 작성하고 각각의 템플릿을 작성한다.

Continue reading

django, ORM raw() vs connection

django를 사용하다보면, 복잡한 sql문을 django ORM으로 만들기가 매우 어려운 경우가 발생한다. 이럴 때, sql을 직접 이용하기 위해서 djanco connection을 사용할 수도 있지만, query 결과를 템플릿으로 전달하는데는 django queryset이 더 유리해 보인다. 1. app/models.py 에 아래와 같은 테이블을 만들고 migrate한다. from django.db import models # Create your models here. class TestData(models.Model): ip = models.GenericIPAddressField() mac = …

Continue reading

django-mptt 사용자 view

이전글 django-mptt로 tree 구조 만들기.에 이어 사용자에게 보여주는 페이지에서 tree구조를 보여주려면, view.py에 view 함수와 template을 만들어주어야한다. 먼저, view.py에 아래와 같이 view함수를 만들어준다. 아래처럼, Category 모델을 모두 불러와서 템플릿에 데이타를 보내는 뷰를 작성한다. from django.shortcuts import render # Create your views here. from django.views.generic import View from .models import Category class CategoryView(View): template_name = ‘tracer/category.html’ def …

Continue reading