Django UpdateView: ValueError: invalid literal for int() with base 10: username

invalid literal for int() with base 10 django
invalid literal for int() with base 10 django migrate
invalid literal for int() with base 10 django save

I have a Django application containing a basic Profile model which extends the User model using the OneToOneField

class Profile(models.Model):
   user = models.OneToOneField(
     User, 
     on_delete=models.CASCADE,
   )

And this is the url pattern for /updateProfile

path('updateProfile/<pk>', views.UpdateProfileView.as_view(), name='update_profile'),

which is being called from the navigation bar of the website as follows:

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

I have utilised the ModelForm class in forms.py as follows:

class update_profile_form(forms.ModelForm):
   class Meta:
     model = Profile
     fields = ('phone_number', 'profile_picture')

And in Views.py the following UpdateView class-based view is invoked:

@method_decorator(login_required, 'dispatch')
class UpdateProfileView(UpdateView):
   model = Profile
   success_url = reverse_lazy('home')
   form_class = update_profile_form
   template_name = 'update_profile.html'

   # this is where the error occurs
   def get_queryset(self):
      return Profile.objects.filter(user=self.request.user) 

My urls.py file contains following patterns:

 urlpatterns = [
   path('', TemplateView.as_view(template_name='Login/home.html'), name='home'),
   path('home/', TemplateView.as_view(template_name='Login/home.html'), name='home'),
   path('updateProfile/<pk>', views.UpdateProfileView.as_view(), name='update_profile'),
 ]

I am unable to determine what combination of user field to use above to render the form in the update_profile.html template.

change this line in html

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

to

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

as request.user returns user object, but the url has pk which is needs an int field

[django] invalid literal for int() with base 10: – Hoshito's blog, File "C:\ProgramData\Anaconda3\lib\site-packages\django\core\ Exception Type: ValueError at /admin/. Exception Value: invalid literal for int() with base 10: '​admin' from django.views.generic import DetailView,UpdateView,DeleteView user=authenticate(username=username,password=password). to reproduce the problem, create the model class below. After, run makemigrations, and migrate. Create a new Person and save then. Include a HistoricalRecords() field and run makemigrations, and migrate. and finally, run populate_history

This is return a object so that problem arise

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

Chnage this to

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

invalid literal for int() with base 10: 'admin', invalid literal for int() with base 10: 'RW' when using Django Filter with Wagtail - django. return int(value) Exception Type: ValueError at /pages/players/ Exception and is accessed via the url pattern site/messages/username where username is I have this UpdateView which when I GET it works fine and when I POST it  invalid literal for int() with base 10: '# NRECS: 1096 ' Baloch: 8: 669: May-24-2020, 02:08 AM Last Post: Larz60+ invalid literal for int() with base 10: '' mrsenorchuck: 5: 1,214: Apr-29-2020, 05:48 AM Last Post: markfilan : ValueError: invalid literal for int() with base 10: ' ' srisrinu: 9: 506: Apr-13-2020, 01:30 PM Last Post: ibreeden

Try this

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

In the html,

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

In the url,

path('updateProfile/<int:pk>/', views.UpdateProfileView.as_view(), name='update_profile'),

invalid literal for int() with base 10: 'RW' when using Django Filter , Added the face_png foreign key and not migrate fails with ValueError: invalid literal for int() with base 10: 'None, remove the foreign key from ArchBase and  Which is an integer. So you told Django to find you the Contender whose user id is the integer 'SUMMERSON', and Django told you "I can't make an integer out of that". You probably want to pass request.user there instead of request.user.get_username() , though, since normally when filtering on a relationship you just use the object -- Django

#30293 (ValueError: invalid literal for int() with base 10: 'None , 10 Django internals a = Article(pub_date=date.today(), headline='Django is cool', Here's what the “base.html” template, including the use of static files, might look like: with the timestamp and username of the person who made the change: The question_id=34 part comes from <int:question_id>. I'm trying to make a profile page with an <owner> argument in the link the owner in the models is a ForeignKey to the user but with any value i submit it saids invalid literal for int() with base 10: models.py

[PDF] Django Documentation, MEDIA_ROOT) >> >> Here is my main urls.py >> from django.contrib import admin import DetailView,UpdateView,DeleteView from django.views.generic import are correct user=authenticate(username=username,password=​password) if user is ValueError at /carts/update/ invalid literal for int() with base 10: '' thats the  I suppose django-secretballot is not adapted to string IDs. ValueError: invalid literal for int() ValueError: invalid literal for int() with base 10 #55.

subject:"Re\: invalid literal for int with base 10", \Python\Python37-32\lib\site-packages\django\views\generic\base.py", line 71, in view return return int(value) ValueError: invalid literal for int() with base 10: '​create' CreateView, UpdateView, DeleteView from django.contrib.auth.mixins import EventCard.objects.all().filter(users__username=request.user.username)​  Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed.

Comments
  • you are using updateview, Why you need query_set there? you can remove that. And also change your link to <a href="{% url 'update_profile' request.user.pk %}">UpdateProfile</a>
  • I tried your solution, the page 404 error occurs. However i can access my template by altering the url from 127.0.0.1:8000/mysite/updateProfile/5 to 127.0.0.1:8000/mysite/updateProfile/1
  • Ok I tried your solution, it returns page 404 not found and the url is also incorrect i.e 127.0.0.1:8000/mysite/updateProfile/5 inplace of 127.0.0.1:8000/venter/updateProfile/1
  • yeah it will because, you app has a app_name i guess? you need to put it infront of the url in the template. if you cant understand, show the main urls and app urls file
  • also if I use Profile.objects.get inplace of Profile.objects.filter it throws an error: 'Profile' model has no attribute 'filter'
  • show the urls else how else i can say what is wrong, and if get gives you error keep the filter
  • this is the url pattern: path('updateProfile/<pk>', views.UpdateProfileView.as_view(), name='update_profile'),
  • it throws Reverse for 'update_profile' with arguments '('',)' not found. Also, note in views.py, the queryset() contains: return Profile.objects.filter(user=self.request.user)
  • You can change profile.user.pk to user.pk or request.user.pk, it depends where your html link is in your template. And you are not going to use queryset in updateview. So you don't need to add queryset there unless you are retriving a lot of users i.e. ListView. Adding to that, you can add get and post function instead using updateview.
  • Ok, tried it, throws a page 404 error, simply because the url link is 127.0.0.1:8000/mysite/updateProfile/5 to 127.0.0.1:8000/mysite/updateProfile/1... what do I do about this?
  • I did not get it? Is it 404 page when you change the pk from 5 to 1 manually in your url and that user does not exists?
  • when pk is 5, I encounter 404, but when I manually change it to id=1 in the url, the template is successfully rendered