here is my urls.py
urlpatterns = [
url(r'^bankcreate/(?:(?P<info_id>[1-9]+)/)?$' , views.bankcreate , name='account-bankcreate'),
]
i have url named account-bankcreate
with an optional argument ... basically if an argument is passed to view its a edit/update operation if not its insert operation
my view starts like this
def bankcreate( requset , info_id = 0 ):
errors = []
default = None
if info_id is not None and int(info_id) > 0 :
try:
default = BankAccounts.objects.get(id=info_id , user_id=requset.user.id)
except BankAccounts.DoesNotExist :
default = None
and it works fine but in the template when i'm trying to set the form action
<form method="post" action="{% url 'account-bankcreate' default.id %}">
if there is no argument passed to view i get this error (it works fine when there is an argument):
NoReverseMatch at /account/bankcreate/
Reverse for 'account-bankcreate' with arguments '('',)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['account/bankcreate/(?:(?P<info_id>[1-9]+)/)?$']
Request Method: GET
Request URL: http://localhost:8000/account/bankcreate/
Django Version: 1.9.6
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'account-bankcreate' with arguments '('',)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['account/bankcreate/(?:(?P<info_id>[1-9]+)/)?$']
Error during template rendering
In template C:\wamp\www\django\paypal\account\templates\account\bankcreate.html, error at line 5
Reverse for 'account-bankcreate' with arguments '('',)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['account/bankcreate/(?:(?P<info_id>[1-9]+)/)?$']
1 {% extends 'master-account.html' %}
2
3 {% block main %}
4 <div class="col-md-7 col-md-offset-2">
5 <form method="post" action="{% url 'account-bankcreate' default.id %}">
6 {% csrf_token %}
7
8
9 {% if errors %}
10 <div class="alert alert-danger">
11 <ul>
12 {% for e in errors %}
13 <li> {{ e }} </li>
14 {% endfor %}
15 </div>
this links works fine
http://localhost:8000/account/bankcreate/1/
this is cousin error
http://localhost:8000/account/bankcreate/