'Attempted relative import beyond top-level package in django

Trying to build a Django app with a signup app within the main app itself

I receive this error message:

from ..signup import views as signup_views
ValueError: attempted relative import beyond top-level package

This is the structure of my app

 ---PeerProgrammingPlatform
 ------peerprogrammingplat
 --------->peerprogrammingplat
 --------->signup

This is my views (in signup):

from django.shortcuts import render, redirect
from django.contrib.auth import login, authenticate
from django.contrib.auth.forms import UserCreationForm

# Create your views here.
def signup(request):
    if request.method == 'POST':
        form = UserCreationForm()
        if form.is_valid():
            form.save()
            username = form.cleaned.data.get('username')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            login(request, user)
            return redirect('home')
    else:
        form = UserCreationForm()
    return render(request, 'signup/register.html', {'form':form})

my urls.py (peerprogrammingplat):

from django.contrib import admin
from django.urls import path
from ..signup import views as signup_views

urlpatterns = [
    path('admin/', admin.site.urls),
    path('register/', signup_views.register, name="register"),
]


Solution 1:[1]

It should be imported only with the name of app:

from signup import views as signup_views

It's because it looks from manage.py level.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1