Cd comand and app name.. On Mon, Mar 28, 2022, 11:57 Samapika Nayak <[email protected]> wrote:
> you need to configure the media files in settings.py > MEDIA_URL = "/media/" > MEDIA_ROOT = BASE_DIR / "media" > also need to configure it in project level urls.py > > if settings.DEBUG: > urlpatterns += static(settings.MEDIA_URL, > document_root=settings.MEDIA_ROOT) > > On Mon, Mar 28, 2022 at 10:04 AM 'Delvin Alexander' via Django users < > [email protected]> wrote: > >> Hello everyone, >> >> I am trying to register a new user by watching the Django tutorial. I >> have created the new user but upon attempting to log the new user in I get >> an, >> >> *"FileNotFoundError at /login/[Errno 2] No such file or directory: >> 'C:\\Users\\delvi\\django_project\\media\\default.jpg'"* >> >> But on my visual code it tells me this, "Exception has occurred: >> ImproperlyConfigured >> >> - >> >> *Requested setting INSTALLED_APPS, but settings are not configured. You >> must either define the environment variable DJANGO_SETTINGS_MODULE or call >> settings.configure() before accessing settings.* >> * File "C:\Users\delvi\django_project\users\models.py", line 2, in >> <module> from django.contrib.auth.models import User"* >> >> >> Here is my model.py file: >> >> from django.db import models >> from django.contrib.auth.models import User >> from PIL import Image >> import os >> from django.core.asgi import get_asgi_application >> >> class Profile(models.Model): >> user = models.OneToOneField(User, on_delete=models.CASCADE) >> image = models.ImageField(default='default.jpg', >> upload_to='profile_pics') >> >> def __str__(self): >> return f'{self.user.username} Profile' >> >> def save(self, *args, **kwargs): >> super(Profile, self).save(*args, **kwargs) >> >> img = Image.open(self.image.path) >> file = open('media') >> >> if img.height > 300 or img.width > 300: >> output_size = (300, 300) >> img.thumbnail(output_size) >> img.save(self.image.path) >> And here is my views.py file for the User folder: >> >> from django.shortcuts import render, redirect >> from django.contrib import messages >> from .forms import UserRegisterForm, UserUpdateForm, ProfileUpdateForm >> from django.contrib.auth.decorators import login_required >> >> >> def register(request): >> if request.method == 'POST': >> form = UserRegisterForm(request.POST) >> if form.is_valid(): >> form.save() >> username = form.cleaned_data.get('username') >> messages.success(request, f'Your Account has been created you >> are now able to log in {username}!') >> return redirect('login') >> else: >> form = UserRegisterForm() >> return render(request, 'users/register.html', {'form': form}) >> >> @login_required >> def profile(request): >> if request.method == 'POST': >> u_form = UserUpdateForm(request.POST, instance=request.user) >> p_form = ProfileUpdateForm(request.POST, request.FILES, >> instance=request.user.profile) >> if u_form.is_valid() and p_form.is_valid(): >> u_form.save() >> p_form.save() >> messages.success(request, f'Your Account has been updated!') >> return redirect('profile') >> else: >> u_form = UserUpdateForm(instance=request.user) >> p_form = ProfileUpdateForm(instance=request.user.profile) >> >> context = { >> 'u_form': u_form, >> 'p_form': p_form, >> } >> >> return render(request, 'users/profile.html', context) >> *Would anyone know the reason why i am getting two mistakes ?* >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-users/e4caa9f7-3715-4486-9c8c-feca7ad31b2an%40googlegroups.com >> <https://groups.google.com/d/msgid/django-users/e4caa9f7-3715-4486-9c8c-feca7ad31b2an%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/CAJG1qUKb2Ar9V-YnTUHRBW6CcgkdSOaQR4Tdm8f79_Ajc2V7pw%40mail.gmail.com > <https://groups.google.com/d/msgid/django-users/CAJG1qUKb2Ar9V-YnTUHRBW6CcgkdSOaQR4Tdm8f79_Ajc2V7pw%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CACvpWiqwYKCPhVBdeKOO31B2rmP9tz6vdnSHz23qqAQ%3D%3D59nqw%40mail.gmail.com.

