๐ก models.py์ AccessLog ํ ์ด๋ธ์ ์์ฑ
๐ก ์ฌ์ฉ์๊ฐ introduce ํ์ด์ง์ ์ ์ํ์ ๋, ์ ์ ๋ก๊ทธ๋ฅผ ๋จ๊ธฐ๊ธฐ
๋ต์
admin.py
from django.contrib import admin
from .models import AccessLog
admin.site.register(AccessLog)
models.py
from django.db import models
class AccessLog(models.Model):
"""
1. default : ๊ธฐ๋ณธ์ ์ผ๋ก ์ฌ์ฉ๋ ๋ ์ง๋ฅผ ์ฌ์ฉ์๊ฐ ์ง์
2. auto_now : ๋ฐ์ดํฐ๊ฐ ์์ ๋ ๋๋ง๋ค ๊ฐฑ์ ๋จ
3. auto_now_add : ๋ฐ์ดํฐ๊ฐ ์์ฑ ๋ ๋ ์๊ฐ์ ๊ธฐ๋ก
"""
created_at = models.DateTimeField("์ ์ ์๊ฐ", auto_now_add=True)
location = models.CharField("์ ์ ๊ฒฝ๋ก", max_length=50)
def __str__(self):
return f"{self.created_at} / {self.location}"
views.py
from django.shortcuts import render
from .models import AccessLog
def introduce(request):
# case 1
"""
access_log = AccessLog()
access_log.location = "introduce"
access_log.save()
"""
# case 2
AccessLog.objects.create(
location="introduce"
)
return render(request, 'introduce.html')
์ฅ๊ณ ํ๊ทธ๋ชจ๋ ๋ค์ด
pip install django-taggit
pip install django-taggit-templatetags2
๐ ๋ค์ด๋ก๋ ํ ํ๋ก์ ํธ settings์ ์ถ๊ฐ
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'tweet',
'user',
'restaurant',
'taggit.apps.TaggitAppConfig',
'taggit_templatetags2',
]
TAGGIT_CASE_INSENSITIVE = True
TAGGIT_LIMIT = 50
1) db.sqlite3 ์ง์ฐ๊ธฐ
2) ๊ฐ ํด๋์ migrations ํด๋์ inti.py๋ง ๋จ๊ธฐ๊ณ ๋ค ์ง์ฐ๊ธฐ
3) ํ๋ก์ ํธ settings.py ์์
DEBUG = False
ALLOWED_HOSTS = ["*"]
4) ๋ ํฌ์งํ ๋ฆฌ ์์ฑ
5) ์ถ๊ฐ
git init
git add .
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/paullee714/mySpartaSns.git
git push -u origin main
1) AWS์์ EC2 ์์ฑ ๋ฐ port ์ค์
EC2 ์๋น์ค ์ ๊ทผ ํ '์ธ์คํด์ค' ํด๋ฆญ
์ธ์คํด์ค ์์
sudo apt-get update
git clone https://github.com/paullee714/mySpartaSns.git
cd mySpartaSns
sudo apt-get install python3-pip -y
pip3 install django django-taggit django-taggit-templatetags2
python3 manage.py makemigrations
python3 manage.py migrate
python3 manage.py runserver 0.0.0.0:8000
4) IPv4 ์ฃผ์ ๋ค์ :8000 ๋ถ์ด๊ณ ์ ์. ์๋ฒ ์ฐ๊ฒฐ ํ์ธ
5) ํฌํธ๋ฒํธ ์์ ๊ธฐ
sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8000
nohup์ผ๋ก ์ฅ๊ณ ์คํํ๊ธฐ
nohup python3 manage.py runserver 0.0.0.0:8000 &
nohup ๋๋ ๋ฒ
ps -ef | grep -i 'manage.py runserver'
kill 20212