0

I'm doing a "forum" app, and I'm moving my project directory from:

rusc
  |-LinkMeta
  |-cela
  |-tag
  |-faq
  |-post
  |-resource
  |-rusc

To:

rusc
 |-LinkMeta
 |-rusc
    |-cela
    |-tag
    |-faq
    |-post
    |-resource

I done for all of them except module Cela, when I try to move cela inside rusc gives me an error:(after changing the references to cela in the project)

Django Version:     1.8.6
Exception Type:     ImportError
Exception Value:    

No module named 'cela'

Exception Location:     
                    C:\Python35\lib\importlib\__init__.py in        
import_module, line 126
Python Executable:  C:\Python35\python.exe
Python Version:     3.5.0
Python Path:    

['C:/Users/zartch/PycharmProjects/Django/rusc',
'C:\\Program Files (x86)\\JetBrains\\PyCharm 4.0.5\\helpers\\pydev',
'C:\\Users\\zartch\\PycharmProjects\\Django\\rusc',
'C:\\Python35\\python35.zip',
'C:\\Python35\\DLLs',
'C:\\Python35\\lib',
'C:\\Python35',
'C:\\Python35\\lib\\site-packages']


Installed Applications:
(
 ...More apps here...
 'rusc.post',
 'rusc.etiqueta',
 'rusc.recurs',
 'rusc.usuari',
 'rusc.cela',
 'rusc.faq',
 'rusc.cela.moderaciomodels')

Traceback:
File "C:\Python35\lib\site-packages\django\core\handlers\base.py" in get_response
  132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:/Users/zartch/PycharmProjects/Django/rusc\rusc\cela\views.py" in ruscView
  23.     return render(request, "rusc.html", {'celas':celas,'notifications': notif})
File "C:\Python35\lib\site-packages\django\shortcuts.py" in render
  67.             template_name, context, request=request, using=using)
File "C:\Python35\lib\site-packages\django\template\loader.py" in render_to_string
  99.         return template.render(context, request)
File "C:\Python35\lib\site-packages\django\template\backends\django.py" in render
  74.         return self.template.render(context)
File "C:\Python35\lib\site-packages\django\template\base.py" in render
  209.                 with context.bind_template(self):
File "C:\Python35\lib\contextlib.py" in __enter__
  59.             return next(self.gen)
File "C:\Python35\lib\site-packages\django\template\context.py" in bind_template
  237.         processors = (template.engine.template_context_processors +
File "C:\Python35\lib\site-packages\django\utils\functional.py" in __get__
  59.         res = instance.__dict__[self.name] = self.func(instance)
File "C:\Python35\lib\site-packages\django\template\engine.py" in template_context_processors
  90.         return tuple(import_string(path) for path in context_processors)
File "C:\Python35\lib\site-packages\django\template\engine.py" in <genexpr>
  90.         return tuple(import_string(path) for path in context_processors)
File "C:\Python35\lib\site-packages\django\utils\module_loading.py" in import_string
  26.     module = import_module(module_path)
File "C:\Python35\lib\importlib\__init__.py" in import_module
  126.     return _bootstrap._gcd_import(name[level:], package, level)

Exception Type: ImportError at /rusc/
Exception Value: No module named 'cela'

It blames on ...\rusc\cela\views.py

from rusc.cela.forms import celaForm
from rusc.cela.models import get_cela, Cela
from rusc.post.models import Post,folksonomia

  def ruscView(request):

    celas = Cela.objects.exclude(tipus='X')
    notif=[]

    if request.user.is_authenticated():
        notif = request.user.notifications.unread()

    return render(request, "rusc.html", {'celas':celas,'notifications': notif})

if I return cela to the top level it just works ok. Any suggestions wood be appreciated.

Debugging def ruscView(request):

def ruscView(request):
   celas = Cela.objects.exclude(tipus='X')
   #The celas object is created [<Cela: Pruebas>]


   notif=[]
   if request.user.is_authenticated():
       notif = request.user.notifications.unread()
   #No user, notif = [], skip if

   return render(request, "rusc.html", {'celas':celas,'notifications': notif})
#This goes to shorcuts.py render, here :
    content = loader.render_to_string(template_name, context, request=request, using=using)
    (returns: No module named 'cela') 
    #Continues on loader.py line 66 method render_to_string
      #Who calls template = get_template(template_name, using=using) (loader.py line 29, with args('rusc.html', _dirs_undefined, None))
      #get_template calls engines which returns a list with the correct folder of the template ('C:/Users/zartch/PycharmProjects/Django/rusc\\rusc\\cela\\templates') and returns correctly the template
      #returns to render_to_string and template.render(context, request) i which is returning the error : "No module named 'cela'"
        #in django.py def render is giving the error when calls "self.template.render(context)"
          # in template\base.py the method render give me the HTML of the page who has to be displayed
          #This returns to render and give me {NoReverseMatch}Reverse for 'rusc.cela' with arguments '(1,)' and keyword arguments '{}' not found. 0 pattern(s) tried: []
      #Returns to render to string returning ({ImportError}No module named 'cela')
    #Then go to base.py get_response and because response= None rise the exception 
9
  • is there an _init_.py file in the rusc folder? Commented Nov 24, 2015 at 14:27
  • Yes an empty _ init _.py , there are modules working inside rusc folder Commented Nov 24, 2015 at 14:29
  • 2
    Maybe it should be from rusc.rusc import cela ? Commented Nov 24, 2015 at 15:06
  • No module named 'rusc.rusc' , but is strange, with rusc.post.models and rusc.faq.models and the others works ok. Also, Pycharm finds the module. Commented Nov 24, 2015 at 22:35
  • How about from cela.forms import celaForm :-) Commented Nov 25, 2015 at 13:53

0

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.