Omar Jandali
Omar Jandali

Reputation: 824

view in one app is not recognized by different view - Django

I have a Django project that I am building. Within the django project I have two apps. one is users and one is accounts. I want to call a view from the acounts app called user_synapse in the users app. I have imported the accounts views python file to import all the methods. I am then calling the method but I am getting an error that says the view method that I am trying to call is not defined. It was working earlier but now it is not working at all. I added the django app name to the settings file and the main urls file. Here is the code I have:

Users app:

views.py file:

#import all references from other apps
from accounts.views import *
from groups.models import *
from groups.views import *
...
# create synapse user
user_synapse(request)

accounts app:

views.py file:

#import all references from other apps
from groups.models import *
from groups.views import *
from users.views import *
from users.models import *

# synapse import statements that are needed
from synapse_pay_rest import Client, Node, Transaction
from synapse_pay_rest import User as SynapseUser
from synapse_pay_rest.models.nodes import AchUsNode
...
# ensure someone is logged in
@login_required
# create a synapse user
def user_synapse(request):
    # grab the logged in user
    user = request.user
    # grab users profile
    profile = Profile.objects.get(user = user)
    # set user items before creating items
    legal_name = profile.first_name + " " + profile.last_name
    note = legal_name + " has just created his synapse profile "
    supp_id = generate_number()
    cip_tag = user.id
    # grab the account type
    account = profile.business
    if account == 'INDIVIDUAL':
        account = False
    if account == 'BUSINESS':
        account = True
    # the following is all of the information that is required in order to make a
    # new user within the Synapse application
    args = {
        'email':str(user.email),
        'phone_number':str(profile.phone),
        'legal_name':str(legal_name),
        'note': str(note),
        'supp_id':str(supp_id),
        'is_business':account,
        'cip_tag':cip_tag,
    }
    # the following is the request to the synapse api as well as the returned
    # json that contains information that needs to ba saved in local database
    create_user = SynapseUser.create(client, **args)
    response = create_user.json
    # the following updates the current profile to add the users synapse id within
    # the local database.
    if response:
        synapse_id = response['_id']
        updateProfile = profile
        updateProfile.synapse_id = synapse_id
        updateProfile.save()

the view does exist. why in the world is it saying that the method is not defined:

NameError at /personal/
name 'user_synapse' is not defined

settings.py file:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'general',
    'users',
    'localflavor',
    'groups',
    'accounts',
]

It was working earlier but now it is not working and I have no idea why.

Upvotes: 0

Views: 407

Answers (1)

Vaibhav
Vaibhav

Reputation: 1234

The problem is that you have a circular import: in users.views.py

from accounts.views import *

in accounts.views.py

from users.views import *

This is not permitted in Python. See import dependency in Python for more info.

Upvotes: 1

Related Questions