beyond top level package error in relative import

后端 未结 13 2441
醉梦人生
醉梦人生 2020-11-22 12:50

It seems there are already quite some questions here about relative import in python 3, but after going through many of them I still didn\'t find the answer for my issue. s

13条回答
  •  迷失自我
    2020-11-22 13:26

    This one didn't work for me as I'm using Django 2.1.3:

    import sys
    sys.path.append("..") # Adds higher directory to python modules path.
    

    I opted for a custom solution where I added a command to the server startup script to copy my shared script into the django 'app' that needed the shared python script. It's not ideal but as I'm only developing a personal website, it fit the bill for me. I will post here again if I can find the django way of sharing code between Django Apps within a single website.

提交回复
热议问题