[Answered ]-Difficulty with managing the error in Django – NoReverseMatch at

2👍

NoReverseMatch at /valoare/MICA/ Reverse for 'contract_list' with arguments '()'
and keyword arguments '{'valoare': 'MICA', 'tip': 'BUNURI'}' not found.
1 pattern(s) tried: ['valoare/(?P<valoare>[A-Z]{4})/(?P<tip>[A-Z]{8})/$']

This error is pretty explicit:

  • your template tries to generate an URI for the contract_list view.
  • url files specifies that this view requires two arguments:
    • valoare, as a 4-alphabetic-character word
    • tip, as a 8-alphabetic-character word
  • but the object you gave it has BUNURI as tip, which is invalid for this url.

Thus, no reverse uri matches.
To fix, you have to either correct your data so the object has a valid tip or, if a 6-character tip is valid, relax the requirement in the uri. For instance to tell it from 4 to 8 characters, you would change it to [A-Z]{4-8}

Leave a comment