django_countries not being recognized for import in my Pycharm

27 Views Asked by At

I am building an ecommerce website with Django and I want to add a dropdown menu for the user to select their state of residence.

Since manually inputting (hardcoding) the list of states in the country would be tedious and unnecessary, I tried using the django_countries package. I have successfully installed the package using pip install django-countries

it comes up in my list of installed packages in my Django project.

I added it to my list of installed apps in my settings.py -

 INSTALLED_APPS = [
     'django.contrib.admin',
     'django.contrib.auth',
     'django.contrib.contenttypes',
     'django.contrib.sessions',
     'django.contrib.messages',
     'django.contrib.staticfiles',
     'ecommerce',
     'accounts',
     'cart',
     'social_django',
     'social_core',
     'anymail',
     'django_countries' ]

So everything seems right, and at the top of my views.py, after all other imports I have -

from django_countries import countries

this is my views funtion that needs the import -

def address_book_create(request):
     user = request.user  # Get the logged-in user
     personal_details = user.personal_details
 
     # Add 'COUNTRIES' to the context dictionary
     context = {
         'user': user,
         'personal_details': personal_details,
         'COUNTRIES': countries,  # Include the country data
     }
 
     return render(request, 'accounts/address_book_create.html', context)

So the line

from django_countries import countries

is being underlined in my Pycharm with the words "Unresolved reference 'django_countries'"

I don't know why.the error is being shown because i actually have the stuff installed. I am not using a virtual environment though. Everything is installed globally. What am I missing?

0

There are 0 best solutions below