0

I'm trying to start my first Django powered project. I have recompiled an existing project. The migrations are completed without any errors, also the development server runs with no issues. The challenge comes when I try to run the project with a uWSGI server. The project environment is as follows Python 2.7, Django 1.9.5, uWSGI 2.0.10 LTS. I have checked similar questions but none has solved my issue thus far. Here is my uWSGI log;

    Traceback (most recent call last): 
    File "/home/admin/apps/smsapp/uwsgi_local.py", line 3, in <module> 
    from smsapp import cache 
    File "/home/admin/apps/smsapp/cache.py", line 3, in <module> 
    from smsapp import models 
    File "/home/admin/apps/smsapp/models.py", line 9, in <module> 
    from django.contrib.auth.models import User, UserManager, Permission 
    File "/home/admin/virtualenv/django/lib/python2.7/site-packages/django/contrib/auth/models.py", line 6, in <module> 
    from django.contrib.contenttypes.models import ContentType 
    File "/home/admin/virtualenv/django/lib/python2.7/site-packages/django/contrib/contenttypes/models.py", line 161, in <module> 
    class ContentType(models.Model): 
    File "/home/admin/virtualenv/django/lib/python2.7/site-packages/django/db/models/base.py", line 102, in __new__ 
    "INSTALLED_APPS." % (models.Model) 
    NameError: global name 'models' is not defined 
    WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x1c7fb60 pid: 3551 (default app) 
    *** uWSGI is running in multiple interpreter mode *** 
    spawned uWSGI master process (pid: 3551) 
    spawned uWSGI worker 1 (pid: 3557, cores: 1) 
    spawned uWSGI worker 2 (pid: 3558, cores: 1) 
    spawned uWSGI worker 3 (pid: 3559, cores: 1) 

Here is my uwsgi_local.py file

    uwsgi_local.py

    from uwsgidecorators import timer 

    from smsapp import cache 


    @timer(5) 
    def update_caches(signum): 
    cache.rebuild_cache()

this is my cache.py

    cache.py

    from django.conf import settings 

    from smsapp import models 


    KEY_NAME = "blacklist" 


    def rebuild_cache(): 
    opt, created = models.Option.objects.get_or_create(name="blacklist") 
    c = opt.content 
    r = c.splitlines() 
    pipe = settings.REDIS.pipeline(transaction=True) 
    pipe.delete(KEY_NAME) 
    for ln in filter(None, r): 
    ss = ln.strip().lower() 
    if ss: 
        pipe.sadd(KEY_NAME, ss) 
    pipe.execute() 


    def is_blacklisted(name): 
    """ 
    Checks if the app is blacklisted 
    @param name: app to check 
    @type name: str 
    @return: True if blacklisted, False otherwise 
    @rtype: bool 
    """ 
    return settings.REDIS.sismember(KEY_NAME, name.lower())

This is my models.py, the full code is too big to post so I will only post exceptions of it, I will post specific line code if requested.

    models.py

    import base64 
    import logging 
    from datetime import timedelta, datetime 
    import re 
    import HTMLParser 

    from ago import human 
    from django.conf import settings 
    from django.contrib.auth.models import User, UserManager, Permission 
    from django.contrib.contenttypes.models import ContentType 
    from django.core.exceptions import AppRegistryNotReady 
    from django.db import models, connection 
    from django.db.models import Q 
    from django.db.models.signals import post_save 
    from django.db.utils import ProgrammingError 
    from django.dispatch import receiver 
    from django.utils import timezone 
    from django.utils.translation import ugettext_lazy as _ 
    from django_countries.fields import CountryField 

    from smsapp import idgen, commands, cfields 


    logger = logging.getLogger(__name__) 

    DB_HTML_CACHE = "__htmlCache" 
    DB_HTML_VERSION = "__htmlVersion" 
    DB_CACHE_TIMEOUT = 30 

Also see a snap of the settings.py

    # Application definition

    INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django_extensions',
    'django_countries',
    'mobile_codes',
    'bootstrap3',
    'smsc',
    'smsapp',
    'django_admin_bootstrapped',
    'django.contrib.admin',
    )

I'm not sure where I'm getting it wrong, any pointers will be appreciated. Thanks in advance....

1 Answer 1

0

I think you have the import from smsapp import models incorrect.

Take a look at this question it may help: Django Import Class From models.py

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for a taking a look at my query, I will take a look later this evening.
I made some progress, I'm now able to start my uwsgi server with the command
(django) [root@devel uwsgi-2.0.10]# ./uwsgi --http :8080 --chdir /home/admin/apps/smsapp --wsgi-file /home/admin/apps/smsapp/smsg/wsgi.py --chmod-socket=666.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.