Google Cloud:无法访问我的DjangoApp的SignUp页面

时间:2019-02-13 04:28:36

标签: google-cloud-platform

在我的Django APP中,我有一个注册部分,由于错误500而无法访问:

服务器错误(500)

我已对此部分执行ping请求:

ping stickersgallito.pe/account/create/

终端响应为:

Ping request could not find host stickersgallito.pe/account/create/. Please check the name and try again.

我当然可以对主机名执行ping操作并得到响应:

(stickers_gallito) D:\web_proyects\stickers_gallito>ping stickersgallito.pe

Pinging stickersgallito.pe [35.211.238.73] with 32 bytes of data:
Reply from 35.211.238.73: bytes=32 time=114ms TTL=67
Reply from 35.211.238.73: bytes=32 time=120ms TTL=67
Reply from 35.211.238.73: bytes=32 time=136ms TTL=67
Reply from 35.211.238.73: bytes=32 time=136ms TTL=67

Ping statistics for 35.211.238.73:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 114ms, Maximum = 136ms, Average = 126ms

urls.py

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('shop.urls')),
    path('cart/', include('cart.urls')),
    path('order/', include('order.urls')),
    path('account/create/', views.signupView, name = 'signup'),
    path('account/login/', views.signinView, name = 'signin'),
    path('account/logout/', views.signoutView, name = 'signout'),
    path('province/', views.get_province, name = 'province')
]

Google云日志:

我在日志中没有看到任何错误:

enter image description here

views.py:

@transaction.atomic
def signupView(request):
    peru = Peru.objects.all()
    department_list = set()
    province_list = set()
    district_list = set()
    for p in peru:
        department_list.add(p.departamento)
    department_list = list(department_list)
    # print("Department List: ", department_list)
    if len(department_list):
        province_list = set(Peru.objects.filter(departamento=department_list[0]).values_list("provincia", flat=True))
        # print("Provice List: ", province_list)
        province_list = list(province_list)
        # print("dfsfs", province_list)
    else:
        province_list = set()
    if len(province_list):
        district_list = set(
            Peru.objects.filter(departamento=department_list[0], provincia=province_list[0]).values_list("distrito",
                                                                                                         flat=True))
        # print("district List: ", district_list)
    else:
        district_list = set()

    if request.method == 'POST':
        print("INSIDE REQUEST.POST")
        print("Department List: ", department_list)
        print("Provice List: ", province_list)
        print("district List: ", district_list)
        print("REQUEST")
        print(request.POST)

        #####

        peru = Peru.objects.all()
        department_list = set()
        province_list = set()
        district_list = set()
        for p in peru:
            department_list.add(p.departamento)
        department_list = list(department_list)
        print("Department List in POST: ", department_list)
        if len(department_list):
            province_list = set(
                Peru.objects.filter(departamento__in=department_list).values_list("provincia", flat=True))

            province_list = list(province_list)
            print("Province LIST in POST", province_list)
        else:
            province_list = set()
        if len(province_list):
            district_list = set(
                Peru.objects.filter(departamento__in=department_list, provincia__in=province_list).values_list("distrito",
                                                                                                             flat=True))
            print("District LIST in POST", district_list)
        else:
            district_list = set()


        #####

        user_form = SignUpForm(request.POST)
        # profile_form = ProfileForm(request.POST) #__init__() missing 2 required positional arguments: 'province_list' and 'department_list'
        profile_form = ProfileForm(district_list, province_list, department_list, request.POST)
        # profile_form = ProfileForm(district_list, province_list, department_list, request.POST, instance=user.profile)


        if  user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            username = user_form.cleaned_data.get('username')
            signup_user = User.objects.get(username=username)
            customer_group = Group.objects.get(name='Clientes')
            customer_group.user_set.add(signup_user)
            raw_password = user_form.cleaned_data.get('password1')
            user.refresh_from_db()  # This will load the Profile created by the Signal
            # print(user_form.cleaned_data)
            print("Form is valid: district_list, province_list, department_list")
            print(district_list, province_list, department_list)
            profile_form = ProfileForm(district_list, province_list, department_list, request.POST,
                                       instance=user.profile)  # Reload the profile form with the profile instance
            profile_form.full_clean()  # Manually clean the form this time. It is implicitly called by "is_valid()" method
            # print(profile_form.cleaned_data)
            profile_form.save()  # Gracefully save the form

            user = authenticate(username=username, password=raw_password)
            login(request, user)

            return redirect('cart:cart_detail')

        else:
            print("INVALID USeR_FORM")
            print(user_form.errors)
            print("INVALID Profile_FORM")
            print(profile_form.errors)

    else:

        user_form = SignUpForm()

        profile_form = ProfileForm(district_list, province_list, department_list)
        print("GET PART!!!!!!")
        print("Deparment_List in GET: ", department_list)
        print("Province_List in GET: ", province_list)
        print("District_List in GET: ", district_list)
        # print('end of profile postdata print')
        # print(profile_form)
        # print("Profile Data:")

    return render(request, 'accounts/signup.html', {
        'user_form': user_form,
        'profile_form': profile_form
    })

0 个答案:

没有答案