質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Django

DjangoはPythonで書かれた、オープンソースウェブアプリケーションのフレームワークです。複雑なデータベースを扱うウェブサイトを開発する際に必要な労力を減らす為にデザインされました。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

1回答

3265閲覧

django 絶対パスでの指定ができず、ModuleNotFoundError: No module named ””となる

tonytony

総合スコア11

Django

DjangoはPythonで書かれた、オープンソースウェブアプリケーションのフレームワークです。複雑なデータベースを扱うウェブサイトを開発する際に必要な労力を減らす為にデザインされました。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2020/06/16 22:06

編集2020/06/17 10:45

python manage.py makemigrations しようとしたところ、

from pairnite.users.models import Profile

ModuleNotFoundError: No module named 'pairnite'

というエラー文に出くわしました。
相対パスでもエラーが出てしまい、ハマっています。
どなたかわかる方いたら教えてください。
やりたいことはusersディレクトリにあるmodels.pyのProfileモデルをインポートしたいです。(pairnite.users.models.pyに記載されているProfile)
呼び出し元のディレクトリはpairnite.chat.models.pyです。
以下、modelsと、インポート元と、settingsです。

chat/models

1from django.db import models 2# ⬇️これがインポートできずエラー出てます。 3from pairnite.users.models import Profile 4 5 6class ChatRoom(models.Model): 7 id = models.AutoField(primary_key=True) 8 9 10class ChatMessage(models.Model): 11 chat_room = models.ForeignKey(ChatRoom, on_delete=models.PROTECT, related_name="message_roomid") 12 user = models.ForeignKey(Profile, on_delete=models.PROTECT, related_name="message_userid") 13 14 15class ChatRoomUser(models.Model): 16 chat_room = models.ForeignKey(ChatRoom, on_delete=models.PROTECT, related_name="roomuser_roomid") 17 user = models.ForeignKey(Profile, on_delete=models.PROTECT, related_name="roomuser_userid") 18

users/models

1from django.core.validators import MaxValueValidator, MinValueValidator 2from django.db import models 3from django.core.mail import send_mail 4from django.contrib.auth.models import PermissionsMixin, UserManager 5from django.contrib.auth.base_user import AbstractBaseUser 6from django.db.models.signals import post_save 7from django.dispatch import receiver 8from django.utils.translation import ugettext_lazy as _ 9from django.utils import timezone 10 11 12 13# OneToOneで、ユーザーモデルに紐付ける 14class Profile(models.Model): 15 # 性別,年齢,ゲームデバイス,通話可能か,通話デバイス,プレイスタイル,プレイ時間帯,建築レベル,一言メッセージ 16 id = models.OneToOneField(User, on_delete=models.CASCADE) 17 username = models.CharField(_('user name'), null=True, max_length=20, blank=True) 18 icon = models.ImageField(blank=True, null=True, upload_to='icon') 19 gender = models.CharField(max_length=20, null=True, blank=True) 20 age = models.IntegerField(validators=[MinValueValidator(12), MaxValueValidator(120)], null=True, blank=True) 21 game_device = models.CharField(max_length=30, null=True, blank=True) 22 voice = models.CharField(max_length=30, null=True, blank=True) 23 voice_device = models.CharField(max_length=30, null=True, blank=True) 24 play_style = models.CharField(max_length=30, null=True, blank=True) 25 play_time = models.CharField(max_length=30, null=True, blank=True) 26 craft_level = models.CharField(max_length=30, null=True, blank=True) 27 one_message = models.CharField(max_length=200, null=True, blank=True) 28 29 def __str__(self): 30 return self.username 31 32 33@receiver(post_save, sender=User) 34def create_user_profile(sender, instance, created, **kwargs): 35 if created: 36 Profile.objects.create(user=instance) 37 38 39@receiver(post_save, sender=User) 40def save_user_profile(sender, instance, **kwargs): 41 instance.profile.save() 42 43

settings.py

1 2 3import os 4 5# Build paths inside the project like this: os.path.join(BASE_DIR, ...) 6BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 7 8 9# Quick-start development settings - unsuitable for production 10# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/ 11 12# SECURITY WARNING: keep the secret key used in production secret! 13SECRET_KEY = '&q9t+ez0k4r_ow$vm!y=mlgxtl4qk12ph58jyvg&#05j+tshe1' 14 15# SECURITY WARNING: don't run with debug turned on in production! 16DEBUG = True 17 18ALLOWED_HOSTS = [] 19 20AUTH_USER_MODEL = 'users.User' 21 22 23# Application definition 24INSTALLED_APPS = [ 25 'django.contrib.admin', 26 'django.contrib.auth', 27 'django.contrib.contenttypes', 28 'django.contrib.sessions', 29 'django.contrib.messages', 30 'django.contrib.staticfiles', 31 'users.apps.UsersConfig', 32 'relations.apps.RelationsConfig', 33 # フォーム処理用 34 "widget_tweaks", 35 'chat.apps.ChatConfig', 36 # # リアルタイムチャット実現用 37 'channels', 38] 39 40 41MIDDLEWARE = [ 42 'django.middleware.security.SecurityMiddleware', 43 'django.contrib.sessions.middleware.SessionMiddleware', 44 'django.middleware.common.CommonMiddleware', 45 'django.middleware.csrf.CsrfViewMiddleware', 46 'django.contrib.auth.middleware.AuthenticationMiddleware', 47 'django.contrib.messages.middleware.MessageMiddleware', 48 'django.middleware.clickjacking.XFrameOptionsMiddleware', 49] 50 51ROOT_URLCONF = 'config.urls' 52 53TEMPLATES = [ 54 { 55 'BACKEND': 'django.template.backends.django.DjangoTemplates', 56 'DIRS': [os.path.join(BASE_DIR, 'templates')], 57 'APP_DIRS': True, 58 'OPTIONS': { 59 'context_processors': [ 60 'django.template.context_processors.debug', 61 'django.template.context_processors.request', 62 'django.contrib.auth.context_processors.auth', 63 'django.contrib.messages.context_processors.messages', 64 ], 65 }, 66 }, 67] 68 69WSGI_APPLICATION = 'config.wsgi.application' 70 71 72# Database 73# https://docs.djangoproject.com/en/3.0/ref/settings/#databases 74 75DATABASES = { 76 'default': { 77 'ENGINE': 'django.db.backends.sqlite3', 78 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 79 } 80} 81 82

ディレクトリ構造

├── Pipfile ├── Pipfile.lock ├── chat │   ├── __init__.py │   ├── __pycache__ │   │   ├── __init__.cpython-37.pyc │   │   ├── admin.cpython-37.pyc │   │   ├── apps.cpython-37.pyc │   │   ├── chat_controller.cpython-37.pyc │   │   ├── models.cpython-37.pyc │   │   ├── urls.cpython-37.pyc │   │   └── views.cpython-37.pyc │   ├── admin.py │   ├── apps.py │   ├── chat_controller.py │   ├── consumers.py │   ├── forms.py │   ├── migrations │   │   ├── __init__.py │   │   └── __pycache__ │   │   └── __init__.cpython-37.pyc │   ├── models.py │   ├── routing.py │   ├── tests.py │   ├── urls.py │   └── views.py ├── config │   ├── __init__.py │   ├── __pycache__ │   │   ├── __init__.cpython-37.pyc │   │   ├── routing.cpython-37.pyc │   │   ├── settings.cpython-37.pyc │   │   ├── urls.cpython-37.pyc │   │   └── wsgi.cpython-37.pyc │   ├── routing.py │   ├── settings.py │   ├── urls.py │   └── wsgi.py ├── db.sqlite3 ├── manage.py ├── media │   └── icon │   ├── 1487784.jpg │   ├── Hi_�\202��\203��\203\210�\203\233�\203��\203\210_1.png │   ├── default.jpg │   ├── �\202��\202��\203��\203��\203��\202��\203��\203\203�\203\210_2020-06-06_13.34.42.png │   ├── �\203��\202��\226\207�\227ZZOO_w.jpg │   └── �\214�\221�\226��\202��\202場�\217模.jpg ├── relations │   ├── __init__.py │   ├── __pycache__ │   │   ├── __init__.cpython-37.pyc │   │   ├── admin.cpython-37.pyc │   │   ├── apps.cpython-37.pyc │   │   ├── forms.cpython-37.pyc │   │   ├── models.cpython-37.pyc │   │   ├── urls.cpython-37.pyc │   │   └── views.cpython-37.pyc │   ├── admin.py │   ├── apps.py │   ├── forms.py │   ├── migrations │   │   ├── 0001_initial.py │   │   ├── __init__.py │   │   └── __pycache__ │   │   ├── 0001_initial.cpython-37.pyc │   │   └── __init__.cpython-37.pyc │   ├── models.py │   ├── tests.py │   ├── urls.py │   └── views.py ├── templates │   ├── base.html │   ├── chat │   │   └── chat.html │   ├── home.html │   ├── index.html │   ├── registration │   │   └── login.html │   ├── relations │   │   ├── dislike.html │   │   └── like.html │   └── users │   ├── delete.html │   ├── detail.html │   ├── mail_change.html │   ├── password_change.html │   ├── password_change_done.html │   ├── signup.html │   └── update.html └── users ├── __init__.py ├── __pycache__ │   ├── __init__.cpython-37.pyc │   ├── admin.cpython-37.pyc │   ├── apps.cpython-37.pyc │   ├── forms.cpython-37.pyc │   ├── mixins.cpython-37.pyc │   ├── models.cpython-37.pyc │   ├── urls.cpython-37.pyc │   └── views.cpython-37.pyc ├── admin.py ├── apps.py ├── forms.py ├── migrations │   ├── 0001_initial.py │   ├── __init__.py │   └── __pycache__ │   ├── 0001_initial.cpython-37.pyc │   ├── 0002_auto_20200606_1415.cpython-37.pyc │   ├── 0003_auto_20200607_1537.cpython-37.pyc │   ├── 0004_auto_20200608_0835.cpython-37.pyc │   └── __init__.cpython-37.pyc ├── mixins.py ├── models.py ├── tests.py ├── urls.py └── views.py

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

ForestSeo

2020/06/16 22:36

makemigtations ではなく、 makemigrations です。 あと、何をimportしようとしているか教えてもらっても良いですか?
quickquip

2020/06/16 23:07 編集

ディレクトリ構造とファイル配置とコマンド実行したときのカレントディレクトリを書きましょう
tonytony

2020/06/17 10:45

更新いたしました。 大変失礼いたしました。
guest

回答1

0

ベストアンサー

以下のようにしたらどうなりますか?

python

1from users.models import Profile

投稿2020/06/19 09:25

hasami

総合スコア1277

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問