passing the correct urls.py pattern









up vote
0
down vote

favorite












I have a button which allows me to add a new botany record, I can click on a 'details' button and to gets the correct record by the botany_id. e.g:



http://localhost:8000/botany/1/
http://localhost:8000/botany/2/
http://localhost:8000/botany/3/


In that view/html I have another button which adds a composition to a related table. It should resolve using http://localhost:8000/botany/1/addcomposition/3/ but it tries http://localhost:8000/botany/addcomposition/3/. This suggests there is an issue in the urls.py which looks like this, I suspect its missing a pattern to account for the botany_id



url(r'^addcomposition/(?P<pk>d+)/$', views.addcomposition, name='addcomposition'),


For clarity I also include the html



<a href="% url 'addcomposition' pk=fraction.fraction_id %" class="btn btn-primary" role="button">+ Composition +</a>









share|improve this question





















  • It is hard to guess without knowing your application structure (for example, the answer may be different depending on where you are including that url). That said, I would expect your URL to be something like ^botany/<botany_id>/addcomposition/<pk>/
    – Paulo Scardine
    Nov 9 at 16:57














up vote
0
down vote

favorite












I have a button which allows me to add a new botany record, I can click on a 'details' button and to gets the correct record by the botany_id. e.g:



http://localhost:8000/botany/1/
http://localhost:8000/botany/2/
http://localhost:8000/botany/3/


In that view/html I have another button which adds a composition to a related table. It should resolve using http://localhost:8000/botany/1/addcomposition/3/ but it tries http://localhost:8000/botany/addcomposition/3/. This suggests there is an issue in the urls.py which looks like this, I suspect its missing a pattern to account for the botany_id



url(r'^addcomposition/(?P<pk>d+)/$', views.addcomposition, name='addcomposition'),


For clarity I also include the html



<a href="% url 'addcomposition' pk=fraction.fraction_id %" class="btn btn-primary" role="button">+ Composition +</a>









share|improve this question





















  • It is hard to guess without knowing your application structure (for example, the answer may be different depending on where you are including that url). That said, I would expect your URL to be something like ^botany/<botany_id>/addcomposition/<pk>/
    – Paulo Scardine
    Nov 9 at 16:57












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a button which allows me to add a new botany record, I can click on a 'details' button and to gets the correct record by the botany_id. e.g:



http://localhost:8000/botany/1/
http://localhost:8000/botany/2/
http://localhost:8000/botany/3/


In that view/html I have another button which adds a composition to a related table. It should resolve using http://localhost:8000/botany/1/addcomposition/3/ but it tries http://localhost:8000/botany/addcomposition/3/. This suggests there is an issue in the urls.py which looks like this, I suspect its missing a pattern to account for the botany_id



url(r'^addcomposition/(?P<pk>d+)/$', views.addcomposition, name='addcomposition'),


For clarity I also include the html



<a href="% url 'addcomposition' pk=fraction.fraction_id %" class="btn btn-primary" role="button">+ Composition +</a>









share|improve this question













I have a button which allows me to add a new botany record, I can click on a 'details' button and to gets the correct record by the botany_id. e.g:



http://localhost:8000/botany/1/
http://localhost:8000/botany/2/
http://localhost:8000/botany/3/


In that view/html I have another button which adds a composition to a related table. It should resolve using http://localhost:8000/botany/1/addcomposition/3/ but it tries http://localhost:8000/botany/addcomposition/3/. This suggests there is an issue in the urls.py which looks like this, I suspect its missing a pattern to account for the botany_id



url(r'^addcomposition/(?P<pk>d+)/$', views.addcomposition, name='addcomposition'),


For clarity I also include the html



<a href="% url 'addcomposition' pk=fraction.fraction_id %" class="btn btn-primary" role="button">+ Composition +</a>






django






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 9 at 16:52









Gary Nobles

18413




18413











  • It is hard to guess without knowing your application structure (for example, the answer may be different depending on where you are including that url). That said, I would expect your URL to be something like ^botany/<botany_id>/addcomposition/<pk>/
    – Paulo Scardine
    Nov 9 at 16:57
















  • It is hard to guess without knowing your application structure (for example, the answer may be different depending on where you are including that url). That said, I would expect your URL to be something like ^botany/<botany_id>/addcomposition/<pk>/
    – Paulo Scardine
    Nov 9 at 16:57















It is hard to guess without knowing your application structure (for example, the answer may be different depending on where you are including that url). That said, I would expect your URL to be something like ^botany/<botany_id>/addcomposition/<pk>/
– Paulo Scardine
Nov 9 at 16:57




It is hard to guess without knowing your application structure (for example, the answer may be different depending on where you are including that url). That said, I would expect your URL to be something like ^botany/<botany_id>/addcomposition/<pk>/
– Paulo Scardine
Nov 9 at 16:57












1 Answer
1






active

oldest

votes

















up vote
1
down vote













if I pas a second variable through the html, e.g. fk=botany.botany_id , add (?P<pk>d+)/ after r'^ then the expected http://localhost:8000/botany/1/addcomposition/3/ is displayed.



Solution, html:



<a href="% url 'addcomposition' fk=botany.botany_id pk=fraction.fraction_id %" class="btn btn-primary" role="button">+ Composition +</a>


urls.py:



url(r'^(?P<fk>d+)addcomposition/(?P<pk>d+)/$', views.addcomposition, name='addcomposition'),





share|improve this answer






















    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',
    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%2f53230100%2fpassing-the-correct-urls-py-pattern%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    if I pas a second variable through the html, e.g. fk=botany.botany_id , add (?P<pk>d+)/ after r'^ then the expected http://localhost:8000/botany/1/addcomposition/3/ is displayed.



    Solution, html:



    <a href="% url 'addcomposition' fk=botany.botany_id pk=fraction.fraction_id %" class="btn btn-primary" role="button">+ Composition +</a>


    urls.py:



    url(r'^(?P<fk>d+)addcomposition/(?P<pk>d+)/$', views.addcomposition, name='addcomposition'),





    share|improve this answer


























      up vote
      1
      down vote













      if I pas a second variable through the html, e.g. fk=botany.botany_id , add (?P<pk>d+)/ after r'^ then the expected http://localhost:8000/botany/1/addcomposition/3/ is displayed.



      Solution, html:



      <a href="% url 'addcomposition' fk=botany.botany_id pk=fraction.fraction_id %" class="btn btn-primary" role="button">+ Composition +</a>


      urls.py:



      url(r'^(?P<fk>d+)addcomposition/(?P<pk>d+)/$', views.addcomposition, name='addcomposition'),





      share|improve this answer
























        up vote
        1
        down vote










        up vote
        1
        down vote









        if I pas a second variable through the html, e.g. fk=botany.botany_id , add (?P<pk>d+)/ after r'^ then the expected http://localhost:8000/botany/1/addcomposition/3/ is displayed.



        Solution, html:



        <a href="% url 'addcomposition' fk=botany.botany_id pk=fraction.fraction_id %" class="btn btn-primary" role="button">+ Composition +</a>


        urls.py:



        url(r'^(?P<fk>d+)addcomposition/(?P<pk>d+)/$', views.addcomposition, name='addcomposition'),





        share|improve this answer














        if I pas a second variable through the html, e.g. fk=botany.botany_id , add (?P<pk>d+)/ after r'^ then the expected http://localhost:8000/botany/1/addcomposition/3/ is displayed.



        Solution, html:



        <a href="% url 'addcomposition' fk=botany.botany_id pk=fraction.fraction_id %" class="btn btn-primary" role="button">+ Composition +</a>


        urls.py:



        url(r'^(?P<fk>d+)addcomposition/(?P<pk>d+)/$', views.addcomposition, name='addcomposition'),






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 9 at 17:29









        Alasdair

        174k25294303




        174k25294303










        answered Nov 9 at 16:57









        Gary Nobles

        18413




        18413



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53230100%2fpassing-the-correct-urls-py-pattern%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

            How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

            Syphilis

            Darth Vader #20