Author's posts

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

django 데이타베이스 모델을 외부 스크립트에서 사용하는 방법

django2.4에서 만든 데이타베이스 모델을 외부 스크립트에서 사용하는 방법 작업환경: python3.7, django2.4 디렉토리 구조는 아래와 같다. 프로젝트 디렉토리 내에 util 디렉토리에 백엔드 스크립트를 위치시키고, 이 스크립트가 django 모델에 orm으로 엑세스 하기를 원할때의 설정 방법이다. sql을 직접 사용하는 방법도 있겠으나, 전체 프로젝트의 일관성을 위해 ORM을 사용하려면 아래와 같은 방법을 사용하면된다. d:\python_project\myproject\ ├─myproject │ └─settings.py ├─static │ └─bootstrap-4.3.1 …

Continue reading

django-mptt로 tree 구조 만들기.

django-mptt, tree 구조를 쉽게(?) 구현하기. 1. 설치 pip install django-mptt 2. 설정하기(project/settings.py) 프로젝트의 settings.py에 아래 내용 추가 INSTALLED_APPS = [ #3’rd party APP ‘mptt’, #django-mptt, 이부분을 추가해야 한다. # below is django default apps… ‘django.contrib.admin’, ‘django.contrib.auth’, ‘django.contrib.contenttypes’, ‘django.contrib.sessions’, ‘django.contrib.messages’, ‘django.contrib.staticfiles’, ] 들여쓰기를 조정하고 싶은경우 아래 부분도 추가해줌(settings.py 맨 마지막에) MPTT_ADMIN_LEVEL_INDENT = 5

Continue reading

CentOS7, TFTP server 설치 사용하기.

CentOS7, TFTP server 설치 사용하기. 작업환경: CentOS 7, firewalld 사용안함, selinux 사용안함. tftp서버는 xinetd에 의해 제어되기때문에, xinetd도 함께 설치해야한다. # yum install tftp-server xinetd xinetd의 tftp 설정확인.(기본 tftp root 디렉토리를 변경하려면, 아래 14번 줄의 /var/lib/tftpboot를 변경하면된다.) # cat /etc/xinetd.d/tftp # default: off # description: The tftp server serves files using the trivial file transfer \ …

Continue reading

Ubuntu 리눅스에 TACACS+ 인증서버 설치하고 시스코 스위치에 적용하기

우분투 리눅스에 TACACS+ 인증서버 설치하기 설치환경: TACACS+ 설치 : ubuntu 18.04, ip address: 192.168.0.6 Cisco switch: C3550, ip address: 192.168.0.200 1. 작업 환경 확인 및 tacacs plus 설치 리눅스 버전 확인 $ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 18.04.1 LTS Release: 18.04 Codename: bionic TACACS+ 설치 $ sudo apt-get …

Continue reading

extreme switch OS 업그레이드 – scp 이용 –

SCP를 이용한 익스트림 스위치 OS 업그레이드 이전 tftp 서버를 이용한 exos 업그레이드에 이어, scp를 이용하여 익스트림 스위치 OS를 업그레이드 한다. ssh 서버: 192.168.0.6 스위치 : 192.168.0.10 exos image file 위치: 192.168.0.6:/home/snowfox/exos/summitX-16.2.5.4-patch1-7.xos 1. ssh를 사용가능하도록 한다. X440-24p.2 # enable ssh2 WARNING: Generating new server host key This could take approximately 15 minutes and cannot be canceled. …

Continue reading

익스트림 스위치 os 업그레이드 – tftp 서버 이용 –

TFTP 서버를 이용한 EXOS 업그레이드 * 작업환경 모델: summit x440-24p, IP 주소:192.168.0.10 TFTP server : 192.168.0.2 작업에 사용한 스위치는 한번도 사용하지 않은 장비로, 아무런 설정이 되어 있지 않은 상태. 1. 장비 os 확인 * X440-24p.1 # sh switch SysName: X440-24p SysLocation: SysContact: support@extremenetworks.com, +1 888 257 3000 System MAC: 00:04:96:9D:13:A0 System Type: X440-24p SysHealth check: …

Continue reading

파이썬, UnicodeDecodeError

파이썬에서 os 명령어를 실행하는 프로그램을 작성하고 실행할때, 때때로 아래와 같은 오류가 발생했다. python3.6 code: import subprocess def linux_cmd(cmd, s): s = s.strip() p = subprocess.Popen([cmd, s], stdout=subprocess.PIPE) r = p.communicate() return r[0] if __name__==’__main__’: k = linux_cmd(‘cat’, ‘a.txt’) print(k)

Continue reading

MySQL, INET_ATON으로 IP 주소 정렬하기

MySQL INET_ATON으로 IP 주소 정렬하기. mysql에서 ip 주소(char type field)를 정렬하면 원하는 결과가 나오지 않는다. mysql> select ip from device_device where category_id=2 order by ip; +—————-+ | ip | +—————-+ | 192.168.100.1 | | 192.168.100.10 | | 192.168.100.11 | … | 192.168.100.35 | | 192.168.100.36 | | 192.168.100.37 | | 192.168.100.4 | | 192.168.100.5 | …

Continue reading

mysql 문자셋으로 인한 django 프로그램에서 db error

Django 에서 아래와 같은 오류 발생 django.db.utils.OperationalError: (1366, “Incorrect string value: ‘\\xE2\\x80\\x8B9F-…’ for column ‘address’ at row 1”) 원인은 mysql 데이타베이스와 테이블의 문자셋이 utf-8이 아니어서 발생했다. database의 문자셋을 확인해보면, latin1 이다. mysql> status; ————– mysql Ver 14.14 Distrib 5.7.25, for Linux (x86_64) using EditLine wrapper Connection id: 462073 Current database: information Current user: information@localhost SSL: …

Continue reading