i have aproblem with my code

33 views
Skip to first unread message

Agni Venus

unread,
Feb 3, 2021, 1:41:51 PM2/3/21
to Django users
data donot save anything when i input it from the website page.
my views.py code 
from django.shortcuts import render
from django.core.files.storage import FileSystemStorage
from .models import profile

def home(request):
up=profile.objects.all()

return render(request, 'home.html' ,{ 'up':up })


def normalupload(request):
if request.method == 'POST' and request.FILES['myfile']:
myfile = request.FILES['myfile']
fs = FileSystemStorage()
filename = fs.save(myfile.name, myfile)
url = fs.url(filename)
new_profile = profile(
name=request.POST['name'],
age=request.POST['age'],
image=url
)
new_profile.save()
redirect('home/')
else:
return redirect('home/')


models.py page
from django.db import models

# Create your models here.

class profile(models.Model):
name= models.CharField(max_length=30)
age=models.IntegerField()
image = models.URLField()

my html page is :
<title>Home</title>
<h3>Working good.</h3>
<br>
<ol>
{% for x in up %}
<li>
{{x.name}}
</li>
{% endfor %}
</ol>

<br>
<br>
<br>
<form action="" method="POST" enctype="multipart/form-data"> {% csrf_token %}
<input type="text" name="name" id=""><br>
<input type="number" name="age" id=""><br>
<input type="file" name="myfile"><br>
<input type="submit" name="submit"><br>



</form>



my urls.py page

from django.contrib import admin
from django.urls import path
from . import views
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('', views.home),
path('home/', views.home),
path('normalupload/', views.normalupload, name="normalupload"),
]

2nd one 

from django.contrib import admin
from django.urls import path
from upload.views import home
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('', home),
]

if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

from django.contrib import admin
from django.urls import path
from upload.views import home
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('', home),
]

if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
from django.contrib import admin
from django.urls import path
from upload.views import home
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('', home),
]

if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Gabriel Araya Garcia

unread,
Feb 3, 2021, 3:16:39 PM2/3/21
to django...@googlegroups.com
Agni:
No, no, the information is not enough. Could you give us exactly which is your problem? you say that it is in a web environment, but what happens in your local host ?
 
Gabriel Araya Garcia
GMI - Desarrollo de Sistemas Informáticos




--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/244dc11f-b877-4198-b994-4a39b809ed75n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages