ModuleNotFoundError: No module named 'api.serlializer' - python

I've installed Django 3.1.4 and djangorestframework 3.12.2.
I am attempting to run makemigrations for a music website I am building and I keep getting this error in the terminal and haven't been able to figure out what is causing it.
(Django_React) PS C:\Users\BB_SO\desktop\dev\Django_React\music_site> python .\manage.py makemigrations Traceback (most recent call last):
File ".\manage.py", line 22, in <module>
main()
File ".\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\core\management\base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\core\management\base.py", line 368, in execute
self.check()
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\core\management\base.py", line 396, in check
databases=databases,
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\core\checks\registry.py", line 70, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
return check_method()
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\urls\resolvers.py", line 408, in check
for pattern in self.url_patterns:
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\urls\resolvers.py", line 589, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\urls\resolvers.py", line 582, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Users\BB_SO\anaconda3\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\BB_SO\desktop\dev\Django_React\music_site\music_site\urls.py", line 19, in <module>
urlpatterns = [path("admin/", admin.site.urls), path("", include("api.urls"))]
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\urls\conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "C:\Users\BB_SO\anaconda3\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\BB_SO\desktop\dev\Django_React\music_site\api\urls.py", line 2, in <module>
from .views import RoomView
File "C:\Users\BB_SO\desktop\dev\Django_React\music_site\api\views.py", line 3, in <module>
from .serlializer import RoomSerializer
ModuleNotFoundError: No module named 'api.serlializer'
Here my serializer.py file content:
from rest_framework import serializer
from .models import Room
class RoomSeralizer(seriarlizers.ModelSerializer):
class Meta:
model = Room
fields = (
"id",
"code",
"host",
"guest_can_pause",
"vote_to_skip",
"created_at",
)
Does anyone know what might be causing this error? I am still very new to coding and am using vscode if that helps at all. Thanks in advance for your help!

In serializer.py Try:
from rest_framework import serializers
Django-rest framework doesn't have any API called serializer.
More: https://www.django-rest-framework.org/api-guide/serializers/

import should be
from rest_framework import serializers

Related

Django ModuleNotFoundError: No module named 'views'

In my Django Project market I created an app called main. In main I created urls.py
main/urls.py:
from django.urls import path
import views
url_patterns = [
path('home/', views.homepage, name='home'),
]
main/views.py:
from django.shortcuts import render, HttpResponse
# Create your views here.
def homepage(request):
return HttpResponse("<h1> Hello World </h1>" )
market/urls.py:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('main.urls'))
]
But when I try to run:
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Python38\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "C:\Python38\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "C:\Python38\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "C:\Python38\lib\site-packages\django\core\management\commands\runserver.py", line 118, in inner_run
self.check(display_num_errors=True)
File "C:\Python38\lib\site-packages\django\core\management\base.py", line 419, in check
all_issues = checks.run_checks(
File "C:\Python38\lib\site-packages\django\core\checks\registry.py", line 76, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "C:\Python38\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "C:\Python38\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
return check_method()
File "C:\Python38\lib\site-packages\django\urls\resolvers.py", line 412, in check
for pattern in self.url_patterns:
File "C:\Python38\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Python38\lib\site-packages\django\urls\resolvers.py", line 598, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Python38\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Python38\lib\site-packages\django\urls\resolvers.py", line 591, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Python38\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\worksapce\jimDjango\market\market\urls.py", line 21, in <module>
path('', include('main.urls'))
File "C:\Python38\lib\site-packages\django\urls\conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "C:\Python38\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\worksapce\jimDjango\market\main\urls.py", line 2, in <module>
import views
ModuleNotFoundError: No module named 'views'
Why won't this run?
Edit:
I also tried replacing import views in main/urls.py with from market.main import views. Doesn't help.
I found two problems with what I did:
I didn't import views.py correctly. I should've used from . import views instead of import views in main/urls.py. (Thanks to user #bdbd)
In main/urls.py I wrote url_patterns instead of urlpatterns

EOF while scanning triple-quoted string literal while creating a TextField value for a django model. (how to correctly concat strings)

this is the model i am creating:
class Notification(models.Model):
user = models.ForeignKey("User", on_delete=models.CASCADE, related_name="notifications")
text = models.TextField()
timestamp = models.DateTimeField(auto_now_add=True)
The "text" field is giving me issues. This is how i am trying to create an instance:
Notification.objects.create(user=instance.post.owner, text=instance.user.username + ' liked your post')
"instance.user.username" is a CharField. What is the correct way of adding that to a string?
this is the complete traceback i am getting:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/home/abhigya/.local/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/abhigya/.local/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/abhigya/.local/lib/python3.8/site-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/abhigya/.local/lib/python3.8/site-packages/django/core/management/base.py", line 368, in execute
self.check()
File "/home/abhigya/.local/lib/python3.8/site-packages/django/core/management/base.py", line 392, in check
all_issues = checks.run_checks(
File "/home/abhigya/.local/lib/python3.8/site-packages/django/core/checks/registry.py", line 70, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "/home/abhigya/.local/lib/python3.8/site-packages/django/core/checks/urls.py", line 40, in check_url_namespaces_unique
all_namespaces = _load_all_namespaces(resolver)
File "/home/abhigya/.local/lib/python3.8/site-packages/django/core/checks/urls.py", line 57, in _load_all_namespaces
url_patterns = getattr(resolver, 'url_patterns', [])
File "/home/abhigya/.local/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/abhigya/.local/lib/python3.8/site-packages/django/urls/resolvers.py", line 589, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/abhigya/.local/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/abhigya/.local/lib/python3.8/site-packages/django/urls/resolvers.py", line 582, in urlconf_module
return import_module(self.urlconf_name)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/abhigya/Documents/WEB-DEV/iiitu/iiitu/urls.py", line 22, in <module>
path('', include("events.urls")),
File "/home/abhigya/.local/lib/python3.8/site-packages/django/urls/conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/abhigya/Documents/WEB-DEV/iiitu/events/urls.py", line 2, in <module>
from . import views
File "/home/abhigya/Documents/WEB-DEV/iiitu/events/views.py", line 583
Notification.objects.create(user=instance.post.owner, text=instance.user.username + ' liked your post')
^
SyntaxError: EOF while scanning triple-quoted string literal
Change
text = models.TextField()
To
text = models.CharField(max_length=20)
You not define the length of the field

migrations are not taking place after pushing my code on heroku...?

Well its been 12 hours and i'm still unable to deploy my project properly. I just dont know what is wrong happening. You guys can see throughing error that such models not exist . But i'm trying to make migrations my heroku run python manage.py makemigrations and it throughing me this traceback. My code is working perfectly fine in local but on the server side this is happening. Please help me out.
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 368, in execute
self.check()
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 396, in check
databases=databases,
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/checks/registry.py", line 70, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/checks/urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/checks/urls.py", line 23, in check_resolver
return check_method()
File "/app/.heroku/python/lib/python3.6/site-packages/django/urls/resolvers.py", line 408, in check
for pattern in self.url_patterns:
File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/app/.heroku/python/lib/python3.6/site-packages/django/urls/resolvers.py", line 589, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/app/.heroku/python/lib/python3.6/site-packages/django/urls/resolvers.py", line 582, in urlconf_module
return import_module(self.urlconf_name)
File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/app/dotescrow/urls.py", line 27, in <module>
path('accounts/', include('accounts.urls',namespace = 'accounts')),
File "/app/.heroku/python/lib/python3.6/site-packages/django/urls/conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
from accounts import views
File "/app/accounts/views.py", line 5, in <module>
from accounts.forms import UserCreateForm,CoustomLoginForm
File "/app/accounts/forms.py", line 54, in <module>
class UserCreateForm(UserCreationForm):
File "/app/.heroku/python/lib/python3.6/site-packages/django/forms/models.py", line 268, in __new__
raise FieldError(message)
django.core.exceptions.FieldError: Unknown field(s) (gender, nationality, age) specified for User
PS C:\Users\AHMED\Dotesrow\dotescrow> heroku run python manage.py makemigrations
Running python manage.py makemigrations on ⬢ dotescrow... up, run.6085 (Free)
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 368, in execute
self.check()
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 396, in check
databases=databases,
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/checks/registry.py", line 70, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/checks/urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/checks/urls.py", line 23, in check_resolver
return check_method()
File "/app/.heroku/python/lib/python3.6/site-packages/django/urls/resolvers.py", line 408, in check
for pattern in self.url_patterns:
File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/app/.heroku/python/lib/python3.6/site-packages/django/urls/resolvers.py", line 589, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/app/.heroku/python/lib/python3.6/site-packages/django/urls/resolvers.py", line 582, in urlconf_module
return import_module(self.urlconf_name)
File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/app/dotescrow/urls.py", line 27, in <module>
path('accounts/', include('accounts.urls',namespace = 'accounts')),
File "/app/.heroku/python/lib/python3.6/site-packages/django/urls/conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/app/accounts/urls.py", line 4, in <module>
from accounts import views
File "/app/accounts/views.py", line 5, in <module>
from accounts.forms import UserCreateForm,CoustomLoginForm
File "/app/accounts/forms.py", line 54, in <module>
class UserCreateForm(UserCreationForm):
File "/app/.heroku/python/lib/python3.6/site-packages/django/forms/models.py", line 268, in __new__
raise FieldError(message)
django.core.exceptions.FieldError: Unknown field(s) (age, nationality, gender) specified for User
Usercreateform
class UserCreateForm(UserCreationForm):
class Meta:
fields = ["first_name","last_name","username","email","password1","password2","age","gender","nationality"]
model = User
Gender = (
('one','Male'),
('two','Female'),
)
widgets ={
'username' : forms.TextInput(attrs={'class':'form-control'}),
'email' : forms.TextInput(attrs={'class':'form-control'}),
'age' : forms.TextInput(attrs={'class':'form-control'}),
'gender' : forms.Select(choices=Gender,attrs={'class': 'form-control'}),
'nationality' : forms.TextInput(attrs={'class':'form-control'}),
'password1' : forms.TextInput(attrs={'class':'form-control'}),
'password2' : forms.TextInput(attrs={'class':'form-control'}),
}
def clean_email(self):
email = self.cleaned_data["email"]
if User.objects.filter(email__iexact=email).exists():
raise forms.ValidationError("Email is invalid")
return email
def clean_age(self):
age = self.cleaned_data["age"]
print(age,'hm here')
if age < 18:
print(age,'hm here')
raise forms.ValidationError("You age should be 18 plus")
return age
def __init__(self,*args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['first_name'].widget.attrs['placeholder'] = ('First name')
self.fields['first_name'].label = ''
self.fields['last_name'].widget.attrs['placeholder'] = ('Last name')
self.fields['last_name'].label = ''
self.fields['username'].widget.attrs['placeholder'] = ('Username')
self.fields['username'].label = ''
self.fields['email'].widget.attrs['placeholder'] = ('Email')
self.fields['email'].label = ''
self.fields['age'].widget.attrs['placeholder'] = ('Age')
self.fields['age'].label = ''
self.fields['gender'].widget.attrs['placeholder'] = ('Gender')
self.fields['gender'].label = ''
self.fields['nationality'].widget.attrs['placeholder'] = ('Nationality')
self.fields['nationality'].label = ''
self.fields['password1'].widget.attrs['placeholder'] = ('Password')
self.fields['password1'].label = ''
self.fields['password2'].widget.attrs['placeholder'] = ('Confirm Password')
self.fields['password2'].label = ''
for fieldname in ['username', 'password1', 'password2']:
self.fields[fieldname].help_text = None
if more code is require then tell me in a comment session. i will update my question with that information.
You should not run makemigrations on heroku. Migrations is something that should be added to your repo and then your deployment plan uses those migration files to execute migrations on the DB.
Heroku has a release phase when python manage.py migrate should be executed. If migrations fail, new code that uses them won't be deployed.
If you don't want to add this phase because you don't feel like it - no problem. Just don't run makemigrations.
If, for some reason, you won't be able to create migrations locally, comment out this form, run makemigrations, run migrate and uncomment this code.
If heroku still complains, repeat these steps ^ on heroku as well.
But the idea is that on heroku you run only
python manage.py migrate (release phase if possible)
gunicorn something something (web dyno)

I'm trying to graphic with django using python but jump IndentationError: expected an indented block

Looks like simple but I'm starting code and I don't know what to do or why this error happened.
What I'm trying is to make an example graphic in django that's all not with success, all the information showed is confusing me.
this is my views.py
from django.shortcuts import render
import matplotlib.pyplot as plt
def home(request):
plt.plot(range(10))
return render(request, 'app1/home.html')
def about(request):
return render(request, 'app1/about.html', {'title': 'About'})
and jump the next error
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/usr/lib/python3.9/threading.py", line 950, in _bootstrap_inner
self.run()
File "/usr/lib/python3.9/threading.py", line 888, in run
self._target(*self._args, **self._kwargs)
File "/home/corbin/ProyectoDB/venv/lib/python3.9/site-packages/django/utils/autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "/home/corbin/ProyectoDB/venv/lib/python3.9/site-packages/django/core/management/commands/runserver.py", line 118, in inner_run
self.check(display_num_errors=True)
File "/home/corbin/ProyectoDB/venv/lib/python3.9/site-packages/django/core/management/base.py", line 392, in check
all_issues = checks.run_checks(
File "/home/corbin/ProyectoDB/venv/lib/python3.9/site-packages/django/core/checks/registry.py", line 70, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "/home/corbin/ProyectoDB/venv/lib/python3.9/site-packages/django/core/checks/urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "/home/corbin/ProyectoDB/venv/lib/python3.9/site-packages/django/core/checks/urls.py", line 23, in check_resolver
return check_method()
File "/home/corbin/ProyectoDB/venv/lib/python3.9/site-packages/django/urls/resolvers.py", line 408, in check
for pattern in self.url_patterns:
File "/home/corbin/ProyectoDB/venv/lib/python3.9/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/corbin/ProyectoDB/venv/lib/python3.9/site-packages/django/urls/resolvers.py", line 589, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/corbin/ProyectoDB/venv/lib/python3.9/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/corbin/ProyectoDB/venv/lib/python3.9/site-packages/django/urls/resolvers.py", line 582, in urlconf_module
return import_module(self.urlconf_name)
File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 790, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/home/corbin/ProyectoDB/LabBD/Web_DB/urls.py", line 21, in <module>
path('', include('app1.urls')),
File "/home/corbin/ProyectoDB/venv/lib/python3.9/site-packages/django/urls/conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 790, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/home/corbin/ProyectoDB/LabBD/app1/urls.py", line 2, in <module>
from . import views
File "/home/corbin/ProyectoDB/LabBD/app1/views.py", line 11
^
IndentationError: expected an indented block
I will apreciate all your help.

How i fix this Unable to import 'django.urls' error?

Errors are:
1. No name 'urls' in module 'django'pylint(no-name-in-module)
Unable to import 'django.urls'
2. No name 'test' in module 'django'pylint(no-name-in-module)
Unable to import 'django.test'pylint(import-error)
3. No name 'http' in module 'django'pylint(no-name-in-module)
Unable to import 'django.http'pylint(import-error)
When I start the server the terminal shows me this -
Watching for file changes with StatReloader
Performing system checks...
Exception in thread django-main-thread:
Traceback (most recent call last):
File "c:\users\aviba\appdata\local\programs\python\python38-32\Lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "c:\users\aviba\appdata\local\programs\python\python38-32\Lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\aviba\Envs\test\lib\site-packages\django\utils\autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "C:\Users\aviba\Envs\test\lib\site-packages\django\core\management\commands\runserver.py", line 117, in inner_run
self.check(display_num_errors=True)
File "C:\Users\aviba\Envs\test\lib\site-packages\django\core\management\base.py", line 387, in check
all_issues = self._run_checks(
File "C:\Users\aviba\Envs\test\lib\site-packages\django\core\management\base.py", line 377, in _run_checks
return checks.run_checks(**kwargs)
File "C:\Users\aviba\Envs\test\lib\site-packages\django\core\checks\registry.py", line 72, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\Users\aviba\Envs\test\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "C:\Users\aviba\Envs\test\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
return check_method()
File "C:\Users\aviba\Envs\test\lib\site-packages\django\urls\resolvers.py", line 399, in check
for pattern in self.url_patterns:
File "C:\Users\aviba\Envs\test\lib\site-packages\django\utils\functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\aviba\Envs\test\lib\site-packages\django\urls\resolvers.py", line 584, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Users\aviba\Envs\test\lib\site-packages\django\utils\functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\aviba\Envs\test\lib\site-packages\django\urls\resolvers.py", line 577, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Users\aviba\Envs\test\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\aviba\djangoproject\firsttry\firsttry\urls.py", line 20, in <module>
path('',include('firstapp.urls')),
File "C:\Users\aviba\Envs\test\lib\site-packages\django\urls\conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "C:\Users\aviba\Envs\test\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\aviba\djangoproject\firsttry\firstapp\urls.py", line 2, in <module>
from . import views
File "C:\Users\aviba\djangoproject\firsttry\firstapp\views.py", line 2, in <module>
from django.http import httpresponse
ImportError: cannot import name 'httpresponse' from 'django.http' (C:\Users\aviba\Envs\test\lib\site-packages\django\http\__init__.py)
urls.py of the app
from django.urls import path
from . import views
urlpattarns = [
path('',views.home, name='home'),
]
views.py of the app
from django.shortcuts import render
from django.http import httpresponse
def home(request):
return httpresponse("Hello Django")
urls.py of the project
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('',include('firstapp.urls')),
path('admin/', admin.site.urls),
]
modules in python are case sensitive, it's HttpResponse not httpresponse
Try this as views.py:
from django.shortcuts import render
from django.http import HttpResponse
def home(request):
return HttpResponse("Hello Django")
Here httpresponse is case sensitive and hence we use it this way.
Read this it might help you more.
Make sure you are using Python3 as interpreter. I had the same issue (using Django 3.1.2) and after selecting the right interpreter (python 3.7.8) it was fixed.

Categories

Resources