using css/ bootstrap webtabs for django forms












0















I run into the following issue with my Django project: I have an profile edit page, where I want the user to be able to edit their profile information, which is seperated in tabs that they can navigate: Profile and Extended Information.
However, the page loads at the Profile tab, but when I navigate to the Extended Information tab, it just opens this tab below the Profile tab, and it doesn't 'replace' the first tab with the second. Consequently, I get a MultiValueDictKeyError error when I only change something in the Extended Information form under that tab. How do I fix the error with the tabs opening below each other? I suspect that my MultiValueDictKeyError also disappears then (but I'm not sure).



Html



{% extends "base.html" %}
{% load bootstrap3 %}

{% block content %}

<!-- Nav tabs -->
<div class="container profile">
<div>
<h1>Edit your details:</h1>
<h3><strong><a href="{% url 'users:profile' %}">{{user.username}}</a></strong></h3>
</div>
<nav>
<div class="nav nav-tabs" id="nav-tab" role="tablist">
<a class="nav-item nav-link active" id="nav-home-tab" data-toggle="tab" href="#nav-home" role="tab" aria-controls="nav-home" aria-selected="true">Profile</a>
<a class="nav-item nav-link" id="nav-profile-tab" data-toggle="tab" href="#nav-profile" role="tab" aria-controls="nav-profile" aria-selected="false">Extended information</a>
</div>
</nav>
<div class="tab-content" id="nav-tabContent">
<div class="tab-pane fade show active" id="nav-home" role="tabpanel" aria-labelledby="nav-home-tab">
<form method="post">
{% csrf_token %}
{% bootstrap_form basic_form %}
<button name="basic_btn" class="btn btn-primary btn-sm" type="Submit" value="basic_form_value">Submit</button>
</form>
</div>
<div class="tab-pane fade" id="nav-profile" role="tabpanel" aria-labelledby="nav-profile-tab">
<form method="post">
{% csrf_token %}
{% bootstrap_form ext_form %}
<button name="ext_btn" class="btn btn-primary btn-sm" type="Submit" value="ext_form_value">Submit</button>
</form>
</div>
</div>


Views.py



def edit_profile(request):

# https://groups.google.com/forum/#!topic/django-users/T9Y67_Nx2qo
basic_form = EditBasicProfileForm(request.POST, instance=request.user)
ext_form = EditExtendedProfileForm(request.POST, instance=request.user)

if request.method == 'POST':
if request.POST['basic_btn'] == "basic_form_value":
basic_form.save()
messages.success(request, ('Your profile was successfully updated!'))
return redirect('users/profile')
elif request.POST['ext_btn'] == "ext_form_value":
ext_form.save()
messages.success(request, ('Your profile was successfully updated!'))
return redirect('users/profile')

else:
basic_form = EditBasicProfileForm(instance=request.user)
ext_form = EditExtendedProfileForm( instance=request.user)
args = {'basic_form': basic_form,'ext_form': ext_form}
return render(request,'users/edit_profile.html',args)


Forms.py



class EditBasicProfileForm(UserChangeForm):

class Meta:
model = User
fields = ('first_name',
'last_name',
'email',
'password'
)

class EditExtendedProfileForm(forms.ModelForm):
class Meta:
fields = ('description','location','fav_genre','fav_book')
model = Profile

def __init__(self, *args, **kwargs):
super().__init__(*args,**kwargs)
self.fields['description'].label = 'Write a little bit about yourself'
self.fields['location'].label = 'Where do you live?'
self.fields['fav_genre'].label = 'What is your favorite genre?'
self.fields['fav_book'].label = 'What is your favorite book?'


Any help is greatly appreciated!










share|improve this question



























    0















    I run into the following issue with my Django project: I have an profile edit page, where I want the user to be able to edit their profile information, which is seperated in tabs that they can navigate: Profile and Extended Information.
    However, the page loads at the Profile tab, but when I navigate to the Extended Information tab, it just opens this tab below the Profile tab, and it doesn't 'replace' the first tab with the second. Consequently, I get a MultiValueDictKeyError error when I only change something in the Extended Information form under that tab. How do I fix the error with the tabs opening below each other? I suspect that my MultiValueDictKeyError also disappears then (but I'm not sure).



    Html



    {% extends "base.html" %}
    {% load bootstrap3 %}

    {% block content %}

    <!-- Nav tabs -->
    <div class="container profile">
    <div>
    <h1>Edit your details:</h1>
    <h3><strong><a href="{% url 'users:profile' %}">{{user.username}}</a></strong></h3>
    </div>
    <nav>
    <div class="nav nav-tabs" id="nav-tab" role="tablist">
    <a class="nav-item nav-link active" id="nav-home-tab" data-toggle="tab" href="#nav-home" role="tab" aria-controls="nav-home" aria-selected="true">Profile</a>
    <a class="nav-item nav-link" id="nav-profile-tab" data-toggle="tab" href="#nav-profile" role="tab" aria-controls="nav-profile" aria-selected="false">Extended information</a>
    </div>
    </nav>
    <div class="tab-content" id="nav-tabContent">
    <div class="tab-pane fade show active" id="nav-home" role="tabpanel" aria-labelledby="nav-home-tab">
    <form method="post">
    {% csrf_token %}
    {% bootstrap_form basic_form %}
    <button name="basic_btn" class="btn btn-primary btn-sm" type="Submit" value="basic_form_value">Submit</button>
    </form>
    </div>
    <div class="tab-pane fade" id="nav-profile" role="tabpanel" aria-labelledby="nav-profile-tab">
    <form method="post">
    {% csrf_token %}
    {% bootstrap_form ext_form %}
    <button name="ext_btn" class="btn btn-primary btn-sm" type="Submit" value="ext_form_value">Submit</button>
    </form>
    </div>
    </div>


    Views.py



    def edit_profile(request):

    # https://groups.google.com/forum/#!topic/django-users/T9Y67_Nx2qo
    basic_form = EditBasicProfileForm(request.POST, instance=request.user)
    ext_form = EditExtendedProfileForm(request.POST, instance=request.user)

    if request.method == 'POST':
    if request.POST['basic_btn'] == "basic_form_value":
    basic_form.save()
    messages.success(request, ('Your profile was successfully updated!'))
    return redirect('users/profile')
    elif request.POST['ext_btn'] == "ext_form_value":
    ext_form.save()
    messages.success(request, ('Your profile was successfully updated!'))
    return redirect('users/profile')

    else:
    basic_form = EditBasicProfileForm(instance=request.user)
    ext_form = EditExtendedProfileForm( instance=request.user)
    args = {'basic_form': basic_form,'ext_form': ext_form}
    return render(request,'users/edit_profile.html',args)


    Forms.py



    class EditBasicProfileForm(UserChangeForm):

    class Meta:
    model = User
    fields = ('first_name',
    'last_name',
    'email',
    'password'
    )

    class EditExtendedProfileForm(forms.ModelForm):
    class Meta:
    fields = ('description','location','fav_genre','fav_book')
    model = Profile

    def __init__(self, *args, **kwargs):
    super().__init__(*args,**kwargs)
    self.fields['description'].label = 'Write a little bit about yourself'
    self.fields['location'].label = 'Where do you live?'
    self.fields['fav_genre'].label = 'What is your favorite genre?'
    self.fields['fav_book'].label = 'What is your favorite book?'


    Any help is greatly appreciated!










    share|improve this question

























      0












      0








      0








      I run into the following issue with my Django project: I have an profile edit page, where I want the user to be able to edit their profile information, which is seperated in tabs that they can navigate: Profile and Extended Information.
      However, the page loads at the Profile tab, but when I navigate to the Extended Information tab, it just opens this tab below the Profile tab, and it doesn't 'replace' the first tab with the second. Consequently, I get a MultiValueDictKeyError error when I only change something in the Extended Information form under that tab. How do I fix the error with the tabs opening below each other? I suspect that my MultiValueDictKeyError also disappears then (but I'm not sure).



      Html



      {% extends "base.html" %}
      {% load bootstrap3 %}

      {% block content %}

      <!-- Nav tabs -->
      <div class="container profile">
      <div>
      <h1>Edit your details:</h1>
      <h3><strong><a href="{% url 'users:profile' %}">{{user.username}}</a></strong></h3>
      </div>
      <nav>
      <div class="nav nav-tabs" id="nav-tab" role="tablist">
      <a class="nav-item nav-link active" id="nav-home-tab" data-toggle="tab" href="#nav-home" role="tab" aria-controls="nav-home" aria-selected="true">Profile</a>
      <a class="nav-item nav-link" id="nav-profile-tab" data-toggle="tab" href="#nav-profile" role="tab" aria-controls="nav-profile" aria-selected="false">Extended information</a>
      </div>
      </nav>
      <div class="tab-content" id="nav-tabContent">
      <div class="tab-pane fade show active" id="nav-home" role="tabpanel" aria-labelledby="nav-home-tab">
      <form method="post">
      {% csrf_token %}
      {% bootstrap_form basic_form %}
      <button name="basic_btn" class="btn btn-primary btn-sm" type="Submit" value="basic_form_value">Submit</button>
      </form>
      </div>
      <div class="tab-pane fade" id="nav-profile" role="tabpanel" aria-labelledby="nav-profile-tab">
      <form method="post">
      {% csrf_token %}
      {% bootstrap_form ext_form %}
      <button name="ext_btn" class="btn btn-primary btn-sm" type="Submit" value="ext_form_value">Submit</button>
      </form>
      </div>
      </div>


      Views.py



      def edit_profile(request):

      # https://groups.google.com/forum/#!topic/django-users/T9Y67_Nx2qo
      basic_form = EditBasicProfileForm(request.POST, instance=request.user)
      ext_form = EditExtendedProfileForm(request.POST, instance=request.user)

      if request.method == 'POST':
      if request.POST['basic_btn'] == "basic_form_value":
      basic_form.save()
      messages.success(request, ('Your profile was successfully updated!'))
      return redirect('users/profile')
      elif request.POST['ext_btn'] == "ext_form_value":
      ext_form.save()
      messages.success(request, ('Your profile was successfully updated!'))
      return redirect('users/profile')

      else:
      basic_form = EditBasicProfileForm(instance=request.user)
      ext_form = EditExtendedProfileForm( instance=request.user)
      args = {'basic_form': basic_form,'ext_form': ext_form}
      return render(request,'users/edit_profile.html',args)


      Forms.py



      class EditBasicProfileForm(UserChangeForm):

      class Meta:
      model = User
      fields = ('first_name',
      'last_name',
      'email',
      'password'
      )

      class EditExtendedProfileForm(forms.ModelForm):
      class Meta:
      fields = ('description','location','fav_genre','fav_book')
      model = Profile

      def __init__(self, *args, **kwargs):
      super().__init__(*args,**kwargs)
      self.fields['description'].label = 'Write a little bit about yourself'
      self.fields['location'].label = 'Where do you live?'
      self.fields['fav_genre'].label = 'What is your favorite genre?'
      self.fields['fav_book'].label = 'What is your favorite book?'


      Any help is greatly appreciated!










      share|improve this question














      I run into the following issue with my Django project: I have an profile edit page, where I want the user to be able to edit their profile information, which is seperated in tabs that they can navigate: Profile and Extended Information.
      However, the page loads at the Profile tab, but when I navigate to the Extended Information tab, it just opens this tab below the Profile tab, and it doesn't 'replace' the first tab with the second. Consequently, I get a MultiValueDictKeyError error when I only change something in the Extended Information form under that tab. How do I fix the error with the tabs opening below each other? I suspect that my MultiValueDictKeyError also disappears then (but I'm not sure).



      Html



      {% extends "base.html" %}
      {% load bootstrap3 %}

      {% block content %}

      <!-- Nav tabs -->
      <div class="container profile">
      <div>
      <h1>Edit your details:</h1>
      <h3><strong><a href="{% url 'users:profile' %}">{{user.username}}</a></strong></h3>
      </div>
      <nav>
      <div class="nav nav-tabs" id="nav-tab" role="tablist">
      <a class="nav-item nav-link active" id="nav-home-tab" data-toggle="tab" href="#nav-home" role="tab" aria-controls="nav-home" aria-selected="true">Profile</a>
      <a class="nav-item nav-link" id="nav-profile-tab" data-toggle="tab" href="#nav-profile" role="tab" aria-controls="nav-profile" aria-selected="false">Extended information</a>
      </div>
      </nav>
      <div class="tab-content" id="nav-tabContent">
      <div class="tab-pane fade show active" id="nav-home" role="tabpanel" aria-labelledby="nav-home-tab">
      <form method="post">
      {% csrf_token %}
      {% bootstrap_form basic_form %}
      <button name="basic_btn" class="btn btn-primary btn-sm" type="Submit" value="basic_form_value">Submit</button>
      </form>
      </div>
      <div class="tab-pane fade" id="nav-profile" role="tabpanel" aria-labelledby="nav-profile-tab">
      <form method="post">
      {% csrf_token %}
      {% bootstrap_form ext_form %}
      <button name="ext_btn" class="btn btn-primary btn-sm" type="Submit" value="ext_form_value">Submit</button>
      </form>
      </div>
      </div>


      Views.py



      def edit_profile(request):

      # https://groups.google.com/forum/#!topic/django-users/T9Y67_Nx2qo
      basic_form = EditBasicProfileForm(request.POST, instance=request.user)
      ext_form = EditExtendedProfileForm(request.POST, instance=request.user)

      if request.method == 'POST':
      if request.POST['basic_btn'] == "basic_form_value":
      basic_form.save()
      messages.success(request, ('Your profile was successfully updated!'))
      return redirect('users/profile')
      elif request.POST['ext_btn'] == "ext_form_value":
      ext_form.save()
      messages.success(request, ('Your profile was successfully updated!'))
      return redirect('users/profile')

      else:
      basic_form = EditBasicProfileForm(instance=request.user)
      ext_form = EditExtendedProfileForm( instance=request.user)
      args = {'basic_form': basic_form,'ext_form': ext_form}
      return render(request,'users/edit_profile.html',args)


      Forms.py



      class EditBasicProfileForm(UserChangeForm):

      class Meta:
      model = User
      fields = ('first_name',
      'last_name',
      'email',
      'password'
      )

      class EditExtendedProfileForm(forms.ModelForm):
      class Meta:
      fields = ('description','location','fav_genre','fav_book')
      model = Profile

      def __init__(self, *args, **kwargs):
      super().__init__(*args,**kwargs)
      self.fields['description'].label = 'Write a little bit about yourself'
      self.fields['location'].label = 'Where do you live?'
      self.fields['fav_genre'].label = 'What is your favorite genre?'
      self.fields['fav_book'].label = 'What is your favorite book?'


      Any help is greatly appreciated!







      python django bootstrap-4






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 20 '18 at 20:45









      CMorganCMorgan

      828




      828
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53401230%2fusing-css-bootstrap-webtabs-for-django-forms%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53401230%2fusing-css-bootstrap-webtabs-for-django-forms%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Guess what letter conforming each word

          Port of Spain

          Run scheduled task as local user group (not BUILTIN)