***.py 에서 html 템플릿으로 딕셔너리 데이타를 넘길때,  혹은 json 형태로 데이터 셋을 받았을때,

 

html 태그를 인식하게 해서 웹화면에 표현하고자 한다면 오토이스케이프를 쓰자.

 

{% autoescape off %}
   {% for key, val in conds.items %}

      ~~~ 내용 ~~~
   {% endfor %}
{% endautoescape %}

  • openssl 설치 확인 (설치가 되어 있지 않다면 openssl 설치 필요)
(base) [root@guest ~]# openssl version
OpenSSL 1.1.1g  21 Apr 2020

 

  • rsa 키파일을 생성한다
(base) [root@guest ~]# openssl genrsa 1024 > rsa.key
Generating RSA private key, 1024 bit long modulus(2 primes)
................+++++
..................+++++
e is 65537 (0x010001)

 

  • cert 파일을 생성한다
(base) [root@guest ~]# openssl req -new -x509 -nodes -sha256 -days 365 -key rsa.key > django.cert
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:ko
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:seoul
Organization Name (eg, company) [Internet Widgits Pty Ltd]:ososoi
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:ososoi
Email Address []:ososoi@daum.net
(base) [root@guest ~]#

-x509

이 옵션은 인증서 요청 대신 자체 서명 된 인증서를 출력합니다. 일반적으로 테스트 인증서 또는 자체 서명 된 루트 CA를 생성하는 데 사용됩니다

 

-days n

옵션을 사용하는 경우 인증서를 인증 할 일 수를 지정합니다. 기본값은 30 일입니다.

 

  • django 프로젝트의 setting.py 을 열어 sslserver 앱을 추가한다.
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'sslserver',
]

 

  • 서버를 실행한다. 필자는 이미 443포트를 사용하고 있기 때문에, 8443 포트를 열어서 사용하도록 하였다.
(base) [root@guest nshopassist]# python manage.py runsslserver --certificate django.cert --key rsa.key 0.0.0.0:8443
Watching for file changes with StatReloader
Validating models...

System check identified no issues (0 silenced).
June 29, 2020 - 21:43:13
Django version 3.0.3, using settings 'nshopassist.settings'
Starting development server at https://0.0.0.0:8443/
Using SSL certificate: django.cert
Using SSL key: rsa.key
Quit the server with CONTROL-C.

 

+ Recent posts