def save_article(request): if request.method == "POST": title = request.POST['title'] content = request.POST['content'] public = request.POST['public'] articulos = Article( title = title, content = content, public = public ) articulos.save() # Crear mensaje de flash que solo se muestra una sola vez messages.success(request, f'Has creado correctamente el articulo {articulos.id}') return redirect('lista_gen_art') else: return HttpResponse("<h2>No se ha podido grabar articulo</h2>")
def create_full_article(request): if request.method == 'POST': formulario = FormArticle(request.POST) if formulario.is_valid(): data_form = formulario.cleaned_data titulo = data_form.get('title') contenido = data_form['content'] publico = data_form.get('public') articulo = Article(title=titulo, content=contenido, public=publico) articulo.save() #crear mensaje cflash (sesion que solo se muestra una vez) messages.success( request, f'Has creado correctamente el articulo {articulo.id}') return redirect('articulos') #return HttpResponse(articulo.title + ' ' + articulo.content + ' ' + str(articulo.public)) else: formulario = FormArticle() return render(request, "create_full_article.html", {'form': formulario})
def save_article(request): """ if request.method == "GET": title = request.GET['title'] if len(title) <= 5: return HttpResponse("<h2>El titulo es muy pequeño</h2>") content = request.GET['content'] public = request.GET['public'] articulo = Article( title = title, content = content, public = public ) """ if request.method == "POST": title = request.POST['title'] if len(title) <= 5: return HttpResponse("<h2>El titulo es muy pequeño</h2>") content = request.POST['content'] public = request.POST['public'] articulo = Article(title=title, content=content, public=public) articulo.save() return HttpResponse( "Articulo Creado: <strong>{}</strong> - {} ".format( articulo.title, articulo.content)) else: return HttpResponse("<h2>No se ha podido crear el articulo</h2>")
def crear_articulo(request,title,content,public): articulo=Article( title=title, content=content, public=public ) articulo.save() return HttpResponse(f"articulo creado: <strong>{articulo.title}</strong>-{articulo.content}")
def grabarArticulo(request, title, content, public): articulo = Article(title=title, content=content, public=public) articulo.save() #crear mesaje flash (sesión que solo se muestra 1 vez) messages.success( request, 'has creado correctamente el articulo {} '.format(articulo.id))
def crear_articulo(request): articulo = Article( title='Champiñones', content='EDF', public=True, ) articulo.save() return HttpResponse(f"Articulo creado: {articulo.title}")
def crear_articulo(request, title, content, public): articulo = Article( title = title, content = content, public = public ) articulo.save() return HttpResponse(f"Articulo Creado: {articulo.title} - {articulo.content} ")
def crear_articulo(request, title='Sin indicar', content='Sin indicar', public=False): # crear el registro articulo = Article(title=title, content=content, public=public) articulo.save() reg = f"<h2>Articulo creado: {articulo.title} - {articulo.content} </h2>" return HttpResponse(reg)
def save_articulo(request): if request.method == 'POST': title = request.POST['title'] content = request.POST['content'] public = request.POST['public'] articulo = Article(title=title, content=content, public=public) articulo.save() return HttpResponse(f"Articulo creado <strong>{articulo.id}</strong>") else: return HttpResponse("<h1>No se creo el articulo</h1>")
def save_article(request): if request.method == 'POST': title = request.POST['title'] content = request.POST['content'] public = request.POST['public'] #Se crea el objeto articulo = Article(title=title, content=content, public=public) articulo.save() #Hay otros métoodos como create return HttpResponse( f"<h3>Articulo Creado: {articulo.title} {articulo.content} {articulo.public}</h3>" ) else: return HttpResponse("<H2>No se ha podido crear el artículo</H2>")
def save_article(request): if request.method == 'POST': title = request.POST['title'] content = request.POST['content'] public = request.POST['public'] articulo = Article(title=title, content=content, public=public) articulo.save() return HttpResponse("Articulo creado") else: return HttpResponse("<h2>No se recibieron los datos</h2>")
def save_article(request): if request.method == 'POST': title = request.POST['title'] content = request.POST['content'] public = request.POST['public'] articulo = Article( title = title, content = content, public = public ) articulo.save() return HttpResponse(f"Articulo creado: {articulo.title}--->{articulo.content}") else: return HttpResponse("<h2>No se ha podido crear el artículo</h2>")
def crear_articulo(request, titulo, contenido, publico): try: articulo = Article( title=titulo, content=contenido, public=publico ) articulo.save() return HttpResponse(f'Articulo created: {articulo.id} <strong>{articulo.title}, {articulo.content} ') except: response = 'Error no se pudo crear, verfica la ruta, o los valores de la url: crear-articulo/titulo/contenido/False or True. ' return HttpResponse(response)
def crear_articulo(request, title, content, public): """ 1.- importat el modelo 2.- paso acontinuacion instanciar la clase """ articulo = Article( title=title, content=content, public=public ) """ 3.- Guardar en la base de datos """ articulo.save() return HttpResponse(f"Articulo creado:{articulo.title} - {articulo.content }")
def save_article(request): if request.method == 'POST': title = request.POST['title'] content = request.POST['content'] public = request.POST['public'] articulo = Article(title=title, content=content, public=public) articulo.save() return HttpResponse( f"Articulo Creado: <strong>{articulo.title} </strong> - {articulo.content}" ) else: return HttpResponse("No ha sido posible")
def save_article(request): if request.method=='POST': title=request.POST['title'] if len(title)<=5: return HttpResponse("El titulo es muy pequeño") content=request.POST['content'] public=request.POST['public'] articulo=Article( title=title, content=content, public=public, ) articulo.save() return HttpResponse(f"articulo creado: <strong>{articulo.title}</strong>-{articulo.content}") else: return HttpResponse("<h2>No se ha podido crear el articulo</h2>")
def create_full_article(request): try: if request.method == 'POST': full_form = FormArticle(request.POST) if full_form.is_valid() : data_form = full_form.cleaned_data title = data_form.get('title') content = data_form['content'] public = data_form.get('public') articulo = Article( title=title, content=content, public=public ) articulo.save() # crear mensaje flash que solo se muestra una vez. messages.success(request, f'Articulo {articulo.id} - {articulo.title } creado exitosamente') return redirect('listar_articulos') # return HttpResponse(title + ' - ' + content + ' - ' + str(public)) else: full_form = FormArticle() return render(request, 'create_full_article.html', { 'formulario' : full_form }) except: response = 'Error ' return HttpResponse(response)
def save_article(request): if request.method == 'POST': title = request.POST['title'] content = request.POST['content'] public = request.POST['public'] articulo = Article( title = title, content = content, public = public ) articulo.save() return HttpResponse(f"Artículo creado: <strong>{articulo.title}</strong> - {articulo.content}") else: return HttpResponse("No se ha podido crear el artículo!!, intentalo mas tarde")
def create_article_full(request): if request.method == 'POST': formulario = FormArticle(request.POST) if formulario.is_valid(): data_form = formulario.cleaned_data title = data_form.get('title') content = data_form['content'] public = data_form['public'] articulo = Article(title=title, content=content, public=public) articulo.save() return HttpResponse("HOLA SOY RUBEN " + title + ' ' + content + ' ' + str(public)) else: formulario = FormArticle() return render(request, 'create_full_article.html', {'form': formulario})
def create_full_article(request): """ formularios como le gustan a django 1.- importar el formulario 2.- extender de la clase ejemplo FormArticle() """ # comprobar datos por post # si llega generameos una peticion # pero si no llega se manda un form vacio if request.method == 'POST': # se mandaran los datos al form # automaticamnte se mandan los datos limpiando formulario = FormArticle(request.POST) # validar formulario if formulario.is_valid(): # recoger datos del formulario limpios data_form = formulario.cleaned_data # se puede acceder con el .get o solo title = data_form.get('title') content = data_form.get('content') public = data_form.get('public') # guardar informacion articulo = Article( title=title, content=content, public=public ) articulo.save() # return HttpResponse(articulo.title) #crear mensaje flash (sesión que solo se muestra una vez) #el primer parametro es la reques para crear la session #el seguno es el mensaje messages.success(request, f'Has creado correctamente el articulo {articulo.title}') return redirect('articulos') else: formulario = FormArticle() return render(request, 'create_full.html', { 'form': formulario })
def create_full_article(request): # validacion del formulario if request.method == 'POST': formulario = formArticle(request.POST) if formulario.is_valid(): data_form = formulario.cleaned_data title = data_form.get('title') content = data_form['content'] public = data_form['public'] # salvar el registro articulo = Article(title=title, content=content, public=public) articulo.save() # crear mensaje flash. mostrado solo una vez messages.success( request, f'Artículo registrado: {articulo.title}', ) # redirigir al listado return redirect('articulos') else: # crear mensaje flash. mostrado solo una vez messages.error(request, f'Error de entrada en el formulario') formulario = formArticle() return render(request, 'create_full_article.html', {'form': formulario}) else: """ genera el formulario vacio """ formulario = formArticle() return render(request, 'create_full_article.html', {'form': formulario})
def crear_articulo(request): if request.method == "POST": title = request.POST['title'] text = request.POST['text'] date = request.POST['date'] time = request.POST['time'] articulo = Article( title=title, content=text, date=date, hour=time, ) try: articulo.save() return redirect("articulos") except: return redirect("articulos")
def save_articulo(request): try: if request.method=='POST': titulo=request.POST['title'] contenido=request.POST['content'] publico=request.POST['public'] articulo = Article( title=titulo, content=contenido, public=publico ) articulo.save() # return HttpResponse(f'Articulo created: {articulo.id} <strong>{articulo.title}, {articulo.content} ') return redirect('listar_articulos') except: response = 'Error no se envian los datos revisa las urls o los metodos GET and POST ' return HttpResponse(response)
def save_articulo(request): """ if request.method == 'GET': titulo = request.GET['title'] contenido = request.GET['content'] publico = request.GET['public'] """ if request.method == 'POST': titulo = request.POST['title'] contenido = request.POST['content'] publico = request.POST['public'] articulo = Article(title=titulo, content=contenido, public=publico) articulo.save() return HttpResponse( f"Articulo creado: {articulo.title} - {articulo.content}") else: return HttpResponse("<h2>No se ha podido guardar el articulo</h2>")
def create_full_article(request): if request.method == 'POST': formulario = formArticulo(request.POST) if formulario.is_valid(): datos_form = formulario.cleaned_data title = datos_form.get('title') content = datos_form.get('content') public = datos_form.get('public') articulos = Article( title = title, content = content, public = public ) articulos.save() # Crear mensaje flash (que es una sesion que solo se muestra 1 vez) messages.success(request, f'Has creado correctamente el articulo {articulos.id}') return redirect('lista_gen_art') else: return HttpResponse("<h2> Formulario invalido </h2>") else: formulario = formArticulo() return render(request, 'create_full_article.html',{ 'form':formulario })
def save_article(request): if request.method == 'POST': title = request.POST["title"] if len(title)<=5: return HttpResponse("El titulo es muy pequeño") content = request.POST["content"] public = request.POST["public"] articulo = Article( title = title, content = content, public = public ) articulo.save() return HttpResponse(f"Articulo Creado: {articulo.title} - {articulo.content} ") else: return HttpResponse("<h2> No se ha podido crear el articulo</h2>")
def save_article(request): if request.method == "GET": title = request.GET['title'] content = request.GET['content'] public = request.GET['public'] try: articulo = Article(title=title, content=content, public=public) articulo.save() #return HttpResponse(f"Articulo creado: {articulo.title} contenido: {articulo.content} creado: {articulo.public}") return redirect('listar_articulos') except: return HttpResponse("<h2ERROR al crear el articulo</h2>") elif request.method == "POST" and len(request.POST['title']) >= 5 and len( request.POST['content']) >= 10: title = request.POST['title'] content = request.POST['content'] public = request.POST['public'] try: articulo = Article(title=title, content=content, public=public) articulo.save() #return HttpResponse(f"Articulo creado - metodo POST funciona: {articulo.title} contenido: {articulo.content} creado: {articulo.public}") return redirect('listar_articulos') except: return HttpResponse("<h2ERROR al crear el articulo</h2>") else: return HttpResponse("<h2>No se pudo crear el articulo</h2>")
def crear_articulo(request, title, content, public): articulo = Article(title=title, content=content, public=public) articulo.save() return HttpResponse("Articulo Creado: <strong>{}</strong> - {} ".format( articulo.title, articulo.content))
def crear_articulo(request, title, content, public): articulo = Article(title=title, content=content, public=public) articulo.save() return redirect('listar_articulos')