0

I am trying to validate a form in a django project and part of the validation is to check if a project exists.

The Environment:

python 3.6.3
django 1.10.8
python-keystoneclient 3.14.0

I have this check currently

def clean_projectname(self):
        submitted_data = self.cleaned_data['projectname']
        newproj = "PROJ-FOO" + submitted_data.upper()
        keystone = osauth.connect()
        try:
            project = keystone.projects.find(name=newproj)
            raise forms.ValidationError('The project name is already taken')
        except NotFound:
            return submitted_data

The try section will return either a project object or it will have a 404 not found Exception.

I have tried to except on the NotFound but Django gives me an error

name 'NotFound' is not defined

I would appreciate help with this.

Lance Haig
  • 332
  • 4
  • 13

2 Answers2

2

Have you imported NotFound from python-keystoneclient? The only way your code would work is if you had this line somewhere else in your file:

from keystoneclient.exceptions import NotFound
Andrew Hare
  • 344,730
  • 71
  • 640
  • 635
0

I'm not aware of the NotFound Exception. Is it something you've written yourself or perhaps you meant to use a similar sound Django exception?

https://docs.djangoproject.com/en/2.0/ref/exceptions/

burling
  • 409
  • 2
  • 5