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)

-- 
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+unsubscr...@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 via email to