from django.urls import path from . import views urlpatterns = [ path('login/', views.login_user, name='login'), path('logout/', views.logout_request, name='logout'), path('register/', views.registration, name='registration'), ]
On Wed, Apr 17, 2024 at 5:16 PM Ana Jiménez <anaturne...@gmail.com> wrote: > the file that says i have wrong is this one: > djangoapp/urls.py > # Uncomment the required imports before adding the code > > from django.shortcuts import render > from django.http import HttpResponseRedirect, HttpResponse > from django.contrib.auth.models import User > from django.shortcuts import get_object_or_404, render, redirect > from django.contrib.auth import logout > from django.contrib import messages > from datetime import datetime > > from django.http import JsonResponse > from django.contrib.auth import login, authenticate > import logging > import json > from django.views.decorators.csrf import csrf_exempt > from .populate import initiate > > > # Get an instance of a logger > logger = logging.getLogger(__name__) > > > # Create your views here. > > # Create a `login_request` view to handle sign in request > @csrf_exempt > def login_user(request): > # Get username and password from request.POST dictionary > data = json.loads(request.body) > username = data['userName'] > password = data['password'] > # Try to check if provide credential can be authenticated > user = authenticate(username=username, password=password) > data = {"userName": username} > if user is not None: > # If user is valid, call login method to login current user > login(request, user) > data = {"userName": username, "status": "Authenticated"} > return JsonResponse(data) > > # Create a `logout_request` view to handle sign out request > def logout_request(request): > logout(request) > data = {"userName": "", "status": "Logged out"} > return JsonResponse(data) > # ... > > # Create a `registration` view to handle sign up request > @csrf_exempt > def registration(request): > context = {} > > data = json.loads(request.body) > username = data['userName'] > password = data['password'] > first_name = data['firstName'] > last_name = data['lastName'] > email = data['email'] > username_exist = False > email_exist = False > try: > # check if user already exists > User.objects.get(username=username) > username_exist = True > except: > #If not, simply log this is a new user > logger.debug("{} is a new user".format(username)) > > #If it is a new user, create a new user > if not username_exist: > #Create user in auth_user table > user = User.objects.create_user(username=username, > first_name=first_name, > last_name=last_name, email=email, password=password) > #Login user and redirect to list page > login(request, user) > data = {"userName":username,"status": "Authenticated"} > return JsonResponse(data) > else : > data = {"userName":username, "error":"Already exists"} > return JsonResponse(data) > # ... > > # # Update the `get_dealerships` view to render the index page with > # a list of dealerships > # def get_dealerships(request): > # ... > > # Create a `get_dealer_reviews` view to render the reviews of a dealer > # def get_dealer_reviews(request,dealer_id): > # ... > > # Create a `get_dealer_details` view to render the dealer details > # def get_dealer_details(request, dealer_id): > # ... > > # Create a `add_review` view to submit a review > # def add_review(request): > # ... > > After that I added this urlpatterns > from django.urls import path from . import views urlpatterns = [ path( > 'login/', views.login_user, name='login'), path('logout/', > views.logout_request, name='logout'), path('register/', > views.registration, name='registration'), > and i still got the following error :( > 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/project/xrwvm-fullstack_developer_capstone/server/djangoenv/lib/python3.8/site-packages/django/core/management/__init__.py", > line 442, in execute_from_command_line > utility.execute() > File > "/home/project/xrwvm-fullstack_developer_capstone/server/djangoenv/lib/python3.8/site-packages/django/core/management/__init__.py", > line 436, in execute > self.fetch_command(subcommand).run_from_argv(self.argv) > File > "/home/project/xrwvm-fullstack_developer_capstone/server/djangoenv/lib/python3.8/site-packages/django/core/management/base.py", > line 412, in run_from_argv > self.execute(*args, **cmd_options) > File > "/home/project/xrwvm-fullstack_developer_capstone/server/djangoenv/lib/python3.8/site-packages/django/core/management/base.py", > line 453, in execute > self.check() > File > "/home/project/xrwvm-fullstack_developer_capstone/server/djangoenv/lib/python3.8/site-packages/django/core/management/base.py", > line 485, in check > all_issues = checks.run_checks( > File > "/home/project/xrwvm-fullstack_developer_capstone/server/djangoenv/lib/python3.8/site-packages/django/core/checks/registry.py", > line 88, in run_checks > new_errors = check(app_configs=app_configs, databases=databases) > File > "/home/project/xrwvm-fullstack_developer_capstone/server/djangoenv/lib/python3.8/site-packages/django/core/checks/urls.py", > line 14, in check_url_config > return check_resolver(resolver) > File > "/home/project/xrwvm-fullstack_developer_capstone/server/djangoenv/lib/python3.8/site-packages/django/core/checks/urls.py", > line 24, in check_resolver > return check_method() > File > "/home/project/xrwvm-fullstack_developer_capstone/server/djangoenv/lib/python3.8/site-packages/django/urls/resolvers.py", > line 494, in check > for pattern in self.url_patterns: > File > "/home/project/xrwvm-fullstack_developer_capstone/server/djangoenv/lib/python3.8/site-packages/django/utils/functional.py", > line 57, in __get__ > res = instance.__dict__[self.name] = self.func(instance) > File > "/home/project/xrwvm-fullstack_developer_capstone/server/djangoenv/lib/python3.8/site-packages/django/urls/resolvers.py", > line 715, in url_patterns > patterns = getattr(self.urlconf_module, "urlpatterns", > self.urlconf_module) > File > "/home/project/xrwvm-fullstack_developer_capstone/server/djangoenv/lib/python3.8/site-packages/django/utils/functional.py", > line 57, in __get__ > res = instance.__dict__[self.name] = self.func(instance) > File > "/home/project/xrwvm-fullstack_developer_capstone/server/djangoenv/lib/python3.8/site-packages/django/urls/resolvers.py", > line 708, 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 843, in exec_module > File "<frozen importlib._bootstrap>", line 219, in > _call_with_frames_removed > File > "/home/project/xrwvm-fullstack_developer_capstone/server/djangoproj/urls.py", > line 24, in <module> > path('djangoapp/', include('djangoapp.urls')), > File > "/home/project/xrwvm-fullstack_developer_capstone/server/djangoenv/lib/python3.8/site-packages/django/urls/conf.py", > line 38, 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 839, in exec_module > File "<frozen importlib._bootstrap_external>", line 976, in get_code > File "<frozen importlib._bootstrap_external>", line 906, in > source_to_code > File "<frozen importlib._bootstrap>", line 219, in > _call_with_frames_removed > File > "/home/project/xrwvm-fullstack_developer_capstone/server/djangoapp/urls.py", > line 27 > logger = logging.getLogger(__name__) > ^ > SyntaxError: invalid syntax > El miércoles, 17 de abril de 2024 a la(s) 10:56:01 a.m. UTC-6, ASAMOAH > EMMANUEL escribió: > >> check your urls.py file to make sure you haven't imported circularly. or >> better still, paste your urls.py here >> >> On Wed, Apr 17, 2024 at 4:47 PM Ana Jiménez <anatu...@gmail.com> wrote: >> >>> hi guys, so i'm doing a project and there's a part that says i need to >>> do the migrations but when i do that i get this error >>> "Traceback (most recent call last): >>> File >>> "/home/project/xrwvm-fullstack_developer_capstone/server/djangoenv/lib/python3.8/site-packages/django/urls/resolvers.py", >>> line 717, in url_patterns >>> iter(patterns) >>> TypeError: 'module' object is not iterable >>> >>> The above exception was the direct cause of the following exception: >>> >>> 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/project/xrwvm-fullstack_developer_capstone/server/djangoenv/lib/python3.8/site-packages/django/core/management/__init__.py", >>> line 442, in execute_from_command_line >>> utility.execute() >>> File >>> "/home/project/xrwvm-fullstack_developer_capstone/server/djangoenv/lib/python3.8/site-packages/django/core/management/__init__.py", >>> line 436, in execute >>> self.fetch_command(subcommand).run_from_argv(self.argv) >>> File >>> "/home/project/xrwvm-fullstack_developer_capstone/server/djangoenv/lib/python3.8/site-packages/django/core/management/base.py", >>> line 412, in run_from_argv >>> self.execute(*args, **cmd_options) >>> File >>> "/home/project/xrwvm-fullstack_developer_capstone/server/djangoenv/lib/python3.8/site-packages/django/core/management/base.py", >>> line 453, in execute >>> self.check() >>> File >>> "/home/project/xrwvm-fullstack_developer_capstone/server/djangoenv/lib/python3.8/site-packages/django/core/management/base.py", >>> line 485, in check >>> all_issues = checks.run_checks( >>> File >>> "/home/project/xrwvm-fullstack_developer_capstone/server/djangoenv/lib/python3.8/site-packages/django/core/checks/registry.py", >>> line 88, in run_checks >>> new_errors = check(app_configs=app_configs, databases=databases) >>> File >>> "/home/project/xrwvm-fullstack_developer_capstone/server/djangoenv/lib/python3.8/site-packages/django/core/checks/urls.py", >>> line 14, in check_url_config >>> return check_resolver(resolver) >>> File >>> "/home/project/xrwvm-fullstack_developer_capstone/server/djangoenv/lib/python3.8/site-packages/django/core/checks/urls.py", >>> line 24, in check_resolver >>> return check_method() >>> File >>> "/home/project/xrwvm-fullstack_developer_capstone/server/djangoenv/lib/python3.8/site-packages/django/urls/resolvers.py", >>> line 495, in check >>> messages.extend(check_resolver(pattern)) >>> File >>> "/home/project/xrwvm-fullstack_developer_capstone/server/djangoenv/lib/python3.8/site-packages/django/core/checks/urls.py", >>> line 24, in check_resolver >>> return check_method() >>> File >>> "/home/project/xrwvm-fullstack_developer_capstone/server/djangoenv/lib/python3.8/site-packages/django/urls/resolvers.py", >>> line 494, in check >>> for pattern in self.url_patterns: >>> File >>> "/home/project/xrwvm-fullstack_developer_capstone/server/djangoenv/lib/python3.8/site-packages/django/utils/functional.py", >>> line 57, in __get__ >>> res = instance.__dict__[self.name] = self.func(instance) >>> File >>> "/home/project/xrwvm-fullstack_developer_capstone/server/djangoenv/lib/python3.8/site-packages/django/urls/resolvers.py", >>> line 725, in url_patterns >>> raise ImproperlyConfigured(msg.format(name=self.urlconf_name)) from e >>> django.core.exceptions.ImproperlyConfigured: The included URLconf >>> '<module 'djangoapp.urls' from >>> '/home/project/xrwvm-fullstack_developer_capstone/server/djangoapp/urls.py'>' >>> does not appear to have any patterns in it. If you see the 'urlpatterns' >>> variable with valid patterns in the file then the issue is probably caused >>> by a circular import. " >>> >>> and i don't know how to solve it :( i'm a beginner in django i need >>> helppp >>> >>> -- >>> 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 django-users...@googlegroups.com. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/django-users/f0b7aa30-2094-47ba-a93f-ed49b506e2ccn%40googlegroups.com >>> <https://groups.google.com/d/msgid/django-users/f0b7aa30-2094-47ba-a93f-ed49b506e2ccn%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >> >> >> -- >> I don't stop when I'm tired, I only stop when the job is done. >> > -- > 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 django-users+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/20de86a9-417a-4b5d-9bad-b8cfcffbc47dn%40googlegroups.com > <https://groups.google.com/d/msgid/django-users/20de86a9-417a-4b5d-9bad-b8cfcffbc47dn%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- I don't stop when I'm tired, I only stop when the job is done. -- 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 django-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CABFHQYz%2BW139NKnNAW4bbMU7SbUMkeavWgTk8EgVjPMeQTfEEw%40mail.gmail.com.