前提・実現したいこと
SQLに繋いだのですが、modelsをimportできず、"attempted relative import with no known parent package"のエラーが出ます。
一応SQLに繋がっていることは確認できたのですが、データを取得してくることができません。
どなたかお助けいただけたら嬉しいです。
ソースコード
<views.py>
from django.shortcuts import render
import requests, json
from requests_html import HTMLSession
from .models import Mydjangodb ※問題箇所
session = HTMLSession()
'''python
def index(request):
template_name = "blog/index.html"
context = {}
if request.method == "GET":
key_word = request.GET['title']
context = {
'title': 'GET',
}
=========省略========= context = { 'words': result[1:2][0], 'd1': d1, } print(context) b = Mydjangodb(id=1) b.save() # INSERTが実行される return render(request, template_name, context)
'''
<models.py>inspectdb使用
from django.db import models
class AuthGroup(models.Model):
name = models.CharField(unique=True, max_length=150)
class Meta: managed = False db_table = 'auth_group'
=========省略=========
class Mydjangodb(models.Model):
google_keywords = models.CharField(max_length=255, blank=True, null=True)
google_url = models.TextField(blank=True, null=True)
google_title = models.CharField(max_length=255, blank=True, null=True)
keywords = models.CharField(max_length=255, blank=True, null=True)
title = models.CharField(max_length=255, blank=True, null=True)
description = models.TextField(blank=True, null=True)
class Meta: managed = False db_table = 'mydjangodb'
あなたの回答
tips
プレビュー