Django_Relation(Profile)
Profile Page 작성
- 자연스러운 follow 흐름을 위한 회원 프로필 페이지 작성하기
url 작성
urlpatterns = [
    path('<username>/', views.profile, name='profile')
]- username을 사용할 때 주의사항 - username을 맨 위로 올리면 문제가 발생한다
- username은 문자열이고 아래에 url도 문자열들이기 때문에 다 맨 위 url에 걸린다.
- variable routing이 문자열일 때 가장 아래로 내릴 것 !
 
View
def profile(request,username) :
    person = get_object_or_404(get_user_model(),username=username)
    context = {
        'person' : person,
    }
    return render(request, 'accounts/profile.html',context)templates
  <h1>{{ person.username}}님의 프로필</h1>
  <hr>
  {% comment %} 작성한 게시글 {% endcomment %}
  <h2>{{person.username}}이 작성한 게시글</h2>
  {% for article in person.article_set.all  %}
    <p>{{article.title}}</p>
  {% endfor %}
  {% comment %} 작성한 댓글 {% endcomment %}
  <h2>{{person.username}}이 작성한 댓글</h2>
  {% for comment in person.comment_set.all %}
    <p>{{comment.content}}</p>
  
  {% endfor %}
  {% comment %} 좋아요를 누른 게시물  {% endcomment %}
  <h2>{{person.username}}이 좋아요를 누른 게시글</h2>
  {% for article in person.like_articles.all %}
    <p>{{article.title}}</p>
  {% endfor %}Author And Source
이 문제에 관하여(Django_Relation(Profile)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@holawan/DjangoRelationProfile저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)