django model is used alone

import them
import sys
import django

pathname = os.path.dirname(os.path.abspath(__file__))
sys.path.append(pathname)

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "MxShop.settings")

django.setup()

from apps.users.models import UserProfile


if __name__ == "__main__":

    user = UserProfile.objects.all()
    for i in user:
        print(i.name,i.gender,i.email)

  

The key point is that the root directory of the project needs to be set to the module directory.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325141297&siteId=291194637