전체 글
-
[Python] Django html 상속 extendsPython/Django 2021. 12. 1. 10:40
# base.html {% load static %} {%block content%} {%endblock%} # users.html {%extends 'myApp/base.html'%} {%block content%} {%if users%} {%for user in users%} User Info Name : {{user.name}} Email : {{user.email}} {%endfor%} {%endif%} {%endblock%}
-
[Python] Django urls.py, views.py 초기 세팅Python/Django 2021. 11. 30. 17:21
# urls.py of project foler from django.contrib import admin from django.urls import path, include from first_app import views urlpatterns = [ path('admin/', admin.site.urls), path('', include('first_app.urls')), ] # urls.py of app folder from django.urls import path from . import views urlpatterns = [ path('', views.index, name='index'), ]
-
[Python] TypeError: __init__() missing 1 required positional argument: 'on_delete'Python/Django 2021. 11. 30. 16:19
class Webpage(models.Model): topic = models.ForeignKey(Topic, on_delete=models.CASCADE,) name = models.CharField(max_length=264, unique=True) url = models.URLField(unique=True) Django 2.0 이후 부터는 ForeignKey를 사용할 경우, 2개의 파라미터를 받게 되어있다. on_delete를 사용할 경우에 대한 설정
-
[Programmers/ Python] 로또의 최고 순위와 최저 순위Algorithm 2021. 11. 30. 10:24
두개의 리스트가 주어진다. 당첨번호와, 내가 뽑은 로또 번호 리스트. 그런데 내가 뽑은 리스트에는 몇몇 번호가 0로 들어오는 이건 미지수이다. 그래서 내가 뽑은 번호와 당첨번호를 비교해서 미지수가 당첨일 경우와 당첨이 아닐 경우 두가지 경우의 수를 계산해서 반환해 주면된다 def solution(lottos, win_nums): rank = [6, 6, 5, 4, 3, 2, 1] unknown = lottos.count(0) # 미지수 구하기 match = 0 for x in win_nums: if x in lottos: match += 1 return rank[match + unknown], rank[match]