Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Listato per risolvere il problema:
- AttributeError at /edit_profile/
- 'function' object has no attribute 'DoesNotExist'
- della funzione edit_profile
- """
- """
- models.py
- """
- class Profile(models.Model):
- id = models.AutoField(primary_key=True)
- user = models.OneToOneField(User, on_delete=models.CASCADE, blank=True, null=True)
- image = models.ImageField(upload_to="profile_pics", blank=True, null=True)
- bio = models.TextField(blank=True, null=True)
- phone_no = models.IntegerField(blank=True, null=True)
- facebook = models.CharField(max_length=300, blank=True, null=True)
- instagram = models.CharField(max_length=300, blank=True, null=True)
- linkedin = models.CharField(max_length=300, blank=True, null=True)
- def __str__(self):
- return str(self.user)
- """
- views.py
- """
- def edit_profile(request):
- try:
- profile = request.user.profile
- except Profile.DoesNotExist:
- profile = Profile(user=request.user)
- if request.method=="POST":
- form = ProfileForm(data=request.POST, files=request.FILES, instance=profile)
- if form.is_valid():
- form.save()
- alert = True
- return render(request, "edit_profile.html", {'alert':alert})
- else:
- form=ProfileForm(instance=profile)
- return render(request, "edit_profile.html", {'form':form})
- """
- urls.py
- """
- from django.urls import path
- from . import views
- from .views import UpdatePostView
- urlpatterns = [
- # blogs
- path("", views.blogs, name="blogs"),
- path("blog/<str:slug>/", views.blogs_comments, name="blogs_comments"),
- path("add_blogs/", views.add_blogs, name="add_blogs"),
- path("edit_blog_post/<str:slug>/", UpdatePostView.as_view(), name="edit_blog_post"),
- path("delete_blog_post/<str:slug>/", views.Delete_Blog_Post, name="delete_blog_post"),
- path("search/", views.search, name="search"),
- # user authentication
- path("register/", views.Register, name="register"),
- path("login/", views.Login, name="login"),
- path("logout/", views.Logout, name="logout"),
- # profile
- path("profile/", views.Profile, name="profile"),
- path("user_profile/<int:myid>/", views.user_profile, name="user_profile"),
- path("edit_profile/", views.edit_profile, name="edit_profile"),
- ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement