django UpdateView: ValueError: неверный литерал для int () с основанием 10: имя пользователя

Во-первых, я думаю, вы должны знать, что есть два типа разрыва и продолжить в Java, которые помечены как break, немеченый разрыв, помечены как продолжены и немечены. Продолжайте, я буду говорить о различии между ними.

class BreakDemo {
public static void main(String[] args) {

    int[] arrayOfInts = 
        { 32, 87, 3, 589,
          12, 1076, 2000,
          8, 622, 127 };
    int searchfor = 12;

    int i;
    boolean foundIt = false;

    for (i = 0; i < arrayOfInts.length; i++) {
        if (arrayOfInts[i] == searchfor) {
            foundIt = true;
            break;//this is an unlabeled break,an unlabeled break statement terminates the innermost switch,for,while,do-while statement.
        }
    }

    if (foundIt) {
        System.out.println("Found " + searchfor + " at index " + i);
    } else {
        System.out.println(searchfor + " not in the array");
    }
}

Инструкция о немедленном разрыве завершает самый внутренний коммутатор, в то время как оператор do-while.

public class BreakWithLabelDemo {
public static void main(String[] args) {
    search:
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 5; j++) {
            System.out.println(i + " - " + j);
            if (j == 3)
                break search;//this is an labeled break.To notice the lab which is search.
        }
    }
}

Обозначенный разрыв прерывает внешний оператор. Если вы javac и java это демо, вы получите:

0 - 0
0 - 1
0 - 2
0 - 3
class ContinueDemo {
public static void main(String[] args) {

    String searchMe = "peter piper picked a " + "peck of pickled peppers";
    int max = searchMe.length();
    int numPs = 0;

    for (int i = 0; i < max; i++) {
        // interested only in p's
        if (searchMe.charAt(i) != 'p')
            continue;//this is an unlabeled continue.

        // process p's
        numPs++;
    }
    System.out.println("Found " + numPs + " p's in the string.");
}

Оператор nonabeled continue пропускает текущую итерацию инструкции for, while, do-while.

public class ContinueWithLabelDemo {
public static void main(String[] args) {
    search:
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 5; j++) {
            System.out.println(i + " - " + j);
            if (j == 3)
                continue search;//this is an labeled continue.Notice the lab which is search
        }
    }
}

Обозначенное выражение continue пропускает текущую итерацию внешнего цикла, помеченного данной меткой, если вы javac и java демо, вы получите:

0 - 0
0 - 1
0 - 2
0 - 3
1 - 0
1 - 1
1 - 2
1 - 3
2 - 0
2 - 1
2 - 2
2 - 3

, если у вас есть какие-либо вопросы, вы можете увидеть учебник по Java этого : введите описание ссылки здесь

0
задан Simran 17 January 2019 в 05:47
поделиться

3 ответа

Попробуйте это

class UpdateProfileView(LoginRequiredMixin, UpdateView):
    login_url = '/add login link/'
    redirect_field_name = 'add login field'
    model = Profile
    success_url = reverse_lazy('home')
    form_class = update_profile_form
    template_name = 'update_profile.html'

   # add post function if you have

В HTML,

<a href="{% url 'update_profile' profile.user.pk %}">UpdateProfile</a>

В URL,

path('updateProfile/<int:pk>/', views.UpdateProfileView.as_view(), name='update_profile'),
0
ответ дан Bidhan Majhi 17 January 2019 в 05:47
поделиться

измените эту строку в html

<a href="{% url 'update_profile' request.user %}">UpdateProfile</a>

на

<a href="{% url 'update_profile' request.user.id %}">UpdateProfile</a>

как request.user returns user object, но url имеет pk, для которого необходимо поле int [ 118]

0
ответ дан Exprator 17 January 2019 в 05:47
поделиться

Это возврат объекта, поэтому возникает проблема.

return Profile.objects.filter(user=self.request.user)

Измените это на

return Profile.objects.filter(user=self.request.user.pk) 
.
0
ответ дан shafik 17 January 2019 в 05:47
поделиться
Другие вопросы по тегам:

Похожие вопросы: