Using choices used in Models.py to route the page in Django












2















I started a project in Django where I am making a new restaurant site. What I thought initially is to make a Model like this:



class Menu(models.Model):
user = models.ForeignKey(User,default=1, on_delete=models.CASCADE)
name = models.CharField("Name of the dish",max_length=30)
category = models.CharField(max_length=20,choices=CATEGORY_CHOICES,default='SP')
description = models.TextField(max_length=300)
dish_image = models.ImageField(upload_to='uploads/')


And I have CATEGORY_CHOICES as CATEGORY_CHOICES = [('L','Lunch'),.....]



Now I have this button on the index page that routes to menu page. In Menu page, I am thinking of displaying the [n] number of tiles with the [name] ( n = number of elements in category choices and name = the full name of it ex:Lunch)



After getting lots of error and figuring out each and every error, I have achieved this task. Now, after that, I want to open the menu of particular category when user clicks in it. Eg: If user clicks 'Lunch' tile, it should route to other page where all the list of the foods with that category are listed. My url pattern is like this:



urlpatterns = [
path('', views.index, name="index"),
path('menu/', views.menu, name="menu"),
path('menu/<str:menu_category>/', views.menu_detail, name="menu_detail"),
]


And I have this view :



def menu_detail(request, menu_category):
menu_list = get_list_or_404(Menu ,category=menu_category)
menu_title = Menu.objects.get(category=menu_category)
return render(request,'restaurant/menu_detail.html',{'menu_list':menu_list,'menu_title':menu_title})


In the Menu template, I am calling it as



<a href="{% url 'menu_detail' menu_category = menus.menu_category %}">


I don't know where I have done wrong. But I am getting ReverseMatchException while browsing ..../menu/ . Maybe it's too complicated for me as I am new to this field. Can anybody please help?










share|improve this question



























    2















    I started a project in Django where I am making a new restaurant site. What I thought initially is to make a Model like this:



    class Menu(models.Model):
    user = models.ForeignKey(User,default=1, on_delete=models.CASCADE)
    name = models.CharField("Name of the dish",max_length=30)
    category = models.CharField(max_length=20,choices=CATEGORY_CHOICES,default='SP')
    description = models.TextField(max_length=300)
    dish_image = models.ImageField(upload_to='uploads/')


    And I have CATEGORY_CHOICES as CATEGORY_CHOICES = [('L','Lunch'),.....]



    Now I have this button on the index page that routes to menu page. In Menu page, I am thinking of displaying the [n] number of tiles with the [name] ( n = number of elements in category choices and name = the full name of it ex:Lunch)



    After getting lots of error and figuring out each and every error, I have achieved this task. Now, after that, I want to open the menu of particular category when user clicks in it. Eg: If user clicks 'Lunch' tile, it should route to other page where all the list of the foods with that category are listed. My url pattern is like this:



    urlpatterns = [
    path('', views.index, name="index"),
    path('menu/', views.menu, name="menu"),
    path('menu/<str:menu_category>/', views.menu_detail, name="menu_detail"),
    ]


    And I have this view :



    def menu_detail(request, menu_category):
    menu_list = get_list_or_404(Menu ,category=menu_category)
    menu_title = Menu.objects.get(category=menu_category)
    return render(request,'restaurant/menu_detail.html',{'menu_list':menu_list,'menu_title':menu_title})


    In the Menu template, I am calling it as



    <a href="{% url 'menu_detail' menu_category = menus.menu_category %}">


    I don't know where I have done wrong. But I am getting ReverseMatchException while browsing ..../menu/ . Maybe it's too complicated for me as I am new to this field. Can anybody please help?










    share|improve this question

























      2












      2








      2








      I started a project in Django where I am making a new restaurant site. What I thought initially is to make a Model like this:



      class Menu(models.Model):
      user = models.ForeignKey(User,default=1, on_delete=models.CASCADE)
      name = models.CharField("Name of the dish",max_length=30)
      category = models.CharField(max_length=20,choices=CATEGORY_CHOICES,default='SP')
      description = models.TextField(max_length=300)
      dish_image = models.ImageField(upload_to='uploads/')


      And I have CATEGORY_CHOICES as CATEGORY_CHOICES = [('L','Lunch'),.....]



      Now I have this button on the index page that routes to menu page. In Menu page, I am thinking of displaying the [n] number of tiles with the [name] ( n = number of elements in category choices and name = the full name of it ex:Lunch)



      After getting lots of error and figuring out each and every error, I have achieved this task. Now, after that, I want to open the menu of particular category when user clicks in it. Eg: If user clicks 'Lunch' tile, it should route to other page where all the list of the foods with that category are listed. My url pattern is like this:



      urlpatterns = [
      path('', views.index, name="index"),
      path('menu/', views.menu, name="menu"),
      path('menu/<str:menu_category>/', views.menu_detail, name="menu_detail"),
      ]


      And I have this view :



      def menu_detail(request, menu_category):
      menu_list = get_list_or_404(Menu ,category=menu_category)
      menu_title = Menu.objects.get(category=menu_category)
      return render(request,'restaurant/menu_detail.html',{'menu_list':menu_list,'menu_title':menu_title})


      In the Menu template, I am calling it as



      <a href="{% url 'menu_detail' menu_category = menus.menu_category %}">


      I don't know where I have done wrong. But I am getting ReverseMatchException while browsing ..../menu/ . Maybe it's too complicated for me as I am new to this field. Can anybody please help?










      share|improve this question














      I started a project in Django where I am making a new restaurant site. What I thought initially is to make a Model like this:



      class Menu(models.Model):
      user = models.ForeignKey(User,default=1, on_delete=models.CASCADE)
      name = models.CharField("Name of the dish",max_length=30)
      category = models.CharField(max_length=20,choices=CATEGORY_CHOICES,default='SP')
      description = models.TextField(max_length=300)
      dish_image = models.ImageField(upload_to='uploads/')


      And I have CATEGORY_CHOICES as CATEGORY_CHOICES = [('L','Lunch'),.....]



      Now I have this button on the index page that routes to menu page. In Menu page, I am thinking of displaying the [n] number of tiles with the [name] ( n = number of elements in category choices and name = the full name of it ex:Lunch)



      After getting lots of error and figuring out each and every error, I have achieved this task. Now, after that, I want to open the menu of particular category when user clicks in it. Eg: If user clicks 'Lunch' tile, it should route to other page where all the list of the foods with that category are listed. My url pattern is like this:



      urlpatterns = [
      path('', views.index, name="index"),
      path('menu/', views.menu, name="menu"),
      path('menu/<str:menu_category>/', views.menu_detail, name="menu_detail"),
      ]


      And I have this view :



      def menu_detail(request, menu_category):
      menu_list = get_list_or_404(Menu ,category=menu_category)
      menu_title = Menu.objects.get(category=menu_category)
      return render(request,'restaurant/menu_detail.html',{'menu_list':menu_list,'menu_title':menu_title})


      In the Menu template, I am calling it as



      <a href="{% url 'menu_detail' menu_category = menus.menu_category %}">


      I don't know where I have done wrong. But I am getting ReverseMatchException while browsing ..../menu/ . Maybe it's too complicated for me as I am new to this field. Can anybody please help?







      django django-models django-templates django-views django-urls






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 2 at 17:10









      Sulove BistaSulove Bista

      436




      436
























          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%2f54010435%2fusing-choices-used-in-models-py-to-route-the-page-in-django%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%2f54010435%2fusing-choices-used-in-models-py-to-route-the-page-in-django%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

          MongoDB - Not Authorized To Execute Command

          How to fix TextFormField cause rebuild widget in Flutter

          Npm cannot find a required file even through it is in the searched directory