Django

    [pinterest clone (25)] get_success_url 함수와 리팩토링

    몇가지의 수정사항 1 class ProfileCreateView(CreateView): model = Profile context_object_name = 'target_profile' form_class = ProfileCreationForm success_url = reverse_lazy('accountapp:hello_world') template_name = 'profileapp/create.html' 보면 success_url로 hello_world를 넘겨주고 있는데 detail로 넘어가는게 더 자연스러워보인다. 하지만 accountapp:detail.html로 코드를 짜면 작동하지 않게되는데 그 이유는 urlpatterns = [ path('hello_world/', hello_world, n..

    [pinterest clone (24)] profileapp update view

    1 views.py class ProfileUpdateView(UpdateView): model = Profile context_object_name = 'target_profile' form_class = ProfileCreationForm success_url = reverse_lazy('accountapp:hello_world') template_name = 'profileapp/update.html' 2 urls.py from django.urls import path from profileapp.views import ProfileCreateView, ProfileUpdateView app_name = 'profileapp' urlpatterns = [ path('create/', Profile..

    [pinterest clone (23)] profileapp create view

    views.py 1 createview 만들기 class ProfileCreateView(CreateView): model = Profile context_object_name = 'target_profile' form_class = ProfileCreationForm success_url = reverse_lazy('accountapp:hello_world') template_name = 'profileapp/create.html' 2 profileapp/templates/profileapp/createview 만들기 {% extends 'base.html'%} {% load bootstrap4 %} {% block content %} Profile Create {% csrf_token %} {% bo..

    [pinterest clone (22)] ModelForm

    Profileapp을 만들기 시작한다. Account와 Profile을 1:1 로 매칭. 1개의 account는 1개의 profile을 가진다. 구성: Profile Image Profile Nickname Profile Message Delete View는 만들지 않을것이고, Detail View도 profile을 따로 보여주는 페이지를 안만들거니까 구현하지 않는다. 1 python manage.py startapp profileapp 2 settings.py에 추가 INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.c..

    [pinterest clone (21)] superuser, media 관련설정

    superuser 생성 : python manage.py createsuperuser media 설정 account app 다음으로 profile app을 만들건데 이미지도 넣을 거기 때문에 이미지 필드를 모델에 설정해줄거다. settings.py에 URL 설정 추가 MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media') MEDIA_URL 설정은 : 127.0.0.1:8000/media/test.jpg 이런걸 바라고 하는거고 MEDIA_ROOT는 : 파일을 올리게되면 platypus에서 media라는 디렉토리가 새로생기면서 올린파일들이 다 저장된다. 장고에서 이미지를 관리할때 쓰는 라이브러리: pillow 설치: pip install pil..

    [pinterest clone (20)] Authentication

    views.py - def hello_world def hello_world(request): if request.user.is_authenticated: if request.method == "POST": temp = request.POST.get('hello_world_input') new_hello_world = HelloWorld() new_hello_world.text = temp new_hello_world.save() return HttpResponseRedirect(reverse('accountapp:hello_world')) else: hello_world_list = HelloWorld.objects.all() return render(request, 'accountapp/hello_w..

    [pinterest clone (19)] Bug fix

    views.py class AccountCreateView(CreateView): model = User form_class = UserCreationForm success_url = reverse_lazy('accountapp:hello_world') template_name = 'accountapp/create.html' class AccountDetailView(DetailView): model = User context_object_name = 'target_user' template_name = 'accountapp/detail.html' class AccountUpdateView(UpdateView): model = User context_object_name = 'target_user' fo..

    [pinterest clone (18)] DeleteView를 이용한 회원탈퇴 구현

    views.py class AccountDeleteView(DeleteView): model = User success_url = reverse_lazy('accountapp:login') template_name = 'accountapp/delete.html' urls.py from django.contrib.auth.views import LoginView, LogoutView from django.urls import path from accountapp.views import hello_world, AccountCreateView, AccountDetailView, AccountUpdateView, AccountDeleteView app_name = 'accountapp' urlpatterns =..

    [pinterest clone (17)] UpdateView를 이용한 비밀번호 변경 구현

    create랑 유사하다. 우선 create 그대로 가져와서 조금만 수정하는식으로. views.py class AccountUpdateView(UpdateView): model = User form_class = UserCreationForm success_url = reverse_lazy('accountapp:hello_world') template_name = 'accountapp/update.html' urls.py from django.contrib.auth.views import LoginView, LogoutView from django.urls import path from accountapp.views import hello_world, AccountCreateView, AccountDeta..

    [pinterest clone (14)] Login / Logout 구현

    장고에 Login view, Logout view 제공된다. 1 urls.py from django.contrib.auth.views import LoginView, LogoutView from django.urls import path from accountapp.views import hello_world, AccountCreateView app_name = 'accountapp' urlpatterns = [ path('hello_world/', hello_world, name='hello_world'), path('login/', LoginView.as_view(template_name='accountapp/login.html'), name='login'), path('logout/', Logout..