R
I tried that but it gave me a different problem. Hang on let me try again….
R
I get: AssertionError: PROGRAM_SERVER_URL not provided by environment variable
R
Then the web address give a 503
R
PROGRAM_SERVER_URL is in my constants.py file and it refers to a website where I grab data from
R
website works without sudo…except one part where I create new user accounts
R
wait a second… I may know the issue
R
nope. Ok, may be I just can’t findit. This entire site worked just fine in a directory called demoSite. I moved it to demoSiteBackup. From that directory I have all these problems. Is there somewhere in particular to look for an issue regarding that? Most of the directory stuff is handled with os calls. like: BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) So it shouldnt matter which directory I move the site too
m0nte cr1st0
Help me, pls https://stackoverflow.com/questions/58648321/how-can-to-start-tasks-with-celery-beat
Anonymous
Hi everyone, Anyone working on dajngo unit testing? What I am looking for? I need to get the response for every rest api for the application and I need to get django database query (postgres) to get the same response. If both match then my test case passes. Problem with 1. understand the existing product django code 2. How to write django database query. Let me explain with an example:- Suppose I want to write unit test for a file upload api, i run that API and get the response from the api. and i have to write django queries to get same data from database. If both pass then my unit test pass.
Sari
please help me.... ValueError at /laporan/create/ Cannot assign "'15'": "laporan_umum.pekerjaan" must be a "pekerjaan" instance.
Vachagan Muradyan
I sell a website (car selling )
Vachagan Muradyan
Django html css
Sari
models.py from django.db import models from django.utils.text import slugify # Create your models here. class pekerjaan (models.Model): nama_pekerjaan = models.CharField(max_length=100) kode = models.IntegerField() satuan = models.CharField(max_length=100) harga = models.IntegerField() def __str__(self): return "{}".format(self.nama_pekerjaan) class material (models.Model): nama_material = models.CharField(max_length=100) kode = models.IntegerField() satuan = models.CharField(max_length=100) harga = models.IntegerField() def __str__(self): return "{}".format(self.nama_material) class laporan_umum (models.Model): # Choices ulp = ( ('karebosi', 'Karebosi'), ('daya', 'Daya'), ('maros', 'Maros'), ('pangkep', 'Pangkep'), ) jenis_temuan = ( ('konstruksi', 'konstruksi'), ('ROW', 'ROW'), ('material', 'material'), ('proteksi', 'proteksi'), ) urgensi = ( ('parah', 'parah'), ('sedang', 'sedang'), ('ringan', 'ringan'), ) padam = ( ('padam', 'padam'), ('tidak padam', 'tidak padam'), ) tim = ( ('PDKB', 'PDKB'), ('KHS', 'KHS'), ('ROw', 'ROW'), ) ulp = models.CharField(max_length=100, choices=ulp) latitude = models.CharField(max_length=100) longtitude = models.CharField(max_length=100) nama_surveyor = models.CharField(max_length=25) feder = models.CharField(max_length=100, null=True) section = models.CharField(max_length=100, null=True) jenis_temuan = models.CharField(max_length=20, choices=jenis_temuan) pekerjaan = models.ForeignKey('pekerjaan', on_delete=models.CASCADE, blank=True) satuan_kerja = models.CharField(max_length=100, null=True) vol_kerja = models.IntegerField(null=True) detail_kerja = models.CharField(max_length=250) alamat = models.CharField(max_length=200) material = models.ForeignKey('material', on_delete=models.CASCADE, blank=True) satuan_material = models.CharField(max_length=100, null=True) vol_material = models.IntegerField(null=True) urgensi = models.CharField(max_length=20, choices=urgensi, null=True) pemadaman = models.CharField(max_length=20, choices=padam, null=True) tim_pemelihara = models.CharField(max_length=20, choices=tim, null=True) tgl_masuk = models.DateField(auto_now_add=True) tgl_kirim = models.DateField(auto_now=True) foto_sebelum = models.ImageField(upload_to='media/foto_sebelum/') foto_sesudah = models.ImageField(upload_to='media/foto_sesudah/', null=True, blank=True) jumlah_pembayaran = models.IntegerField(null=True, blank=True) slug = models.SlugField(blank=True, editable=False) def __str__(self): return "{}. {}".format(self.id,self.ulp) form.py from django import forms from .models import laporan_umum class LaporanForm(forms.ModelForm): class Meta: model = laporan_umum fields = [ 'ulp', 'latitude', 'longtitude', 'nama_surveyor', 'feder', 'section', 'jenis_temuan', 'pekerjaan', 'vol_kerja', 'satuan_kerja', 'detail_kerja', 'alamat', 'material', 'vol_material', 'satuan_material', 'urgensi', 'pemadaman', 'tim_pemelihara', 'foto_sebelum', ] views.py
Sari
views.py
Sari
views.py from django.shortcuts import render, redirect from django.views.generic import TemplateView from django.contrib.auth import authenticate, login, logout from django.contrib.auth.decorators import login_required from .forms import LaporanForm from .models import laporan_umum # Create your views here. def index (request): context = { 'page_title' : 'Selamat Datang | PLN', 'heading' : 'Silahkan Login', } if request.method == "POST": username_login = request.POST['username'] password_login = request.POST['password'] user = authenticate(request, username=username_login, password=password_login) if user is not None: login(request, user) return redirect('laporan:create') else: return redirect('index') return render(request, 'sur_teknik/index.html', context) def create(request): laporan_form = LaporanForm() if request.method == 'POST': laporan_umum.objects.create( ulp = request.POST.get('ulp'), latitude = request.POST.get('latitude'), longtitude = request.POST.get('longtitude'), nama_surveyor = request.POST.get('nama_surveyor'), feder = request.POST.get('feder'), section = request.POST.get('section'), jenis_temuan = request.POST.get('jenis_temuan'), pekerjaan = request.POST.get('pekerjaan'), vol_kerja = request.POST.get('vol_kerja'), satuan_kerja = request.POST.get('satuan_kerja'), detail_kerja = request.POST.get('detail_kerja'), alamat = request.POST.get('alamat'), material = request.POST.get('material'), vol_material = request.POST.get('vol_material'), satuan_material = request.POST.get('satuan_material'), urgensi = request.POST.get('urgensi'), pemadaman = request.POST.get('pemadaman'), tim_pemelihara = request.POST.get('tim_pemelihara'), foto_sebelum = request.POST.get('foto_sebelum'), ) return redirect('laporan:lihat') context = { 'page_title':'Selamat Datang | PLN', 'heading' : 'Masukkan Laporan Anda', 'post_form' : laporan_form, } return render(request,'sur_teknik/create.html',context) def logoutView(request): context = { 'page_title' : 'Selamat Datang | PLN', 'heading' : 'Terima Kasih Atas Laporan Anda', } if request.method == "POST": if request.POST["logout"] == "Submit": logout(request) return redirect('index') return render(request, 'sur_teknik/logout.html', context)
Денис
I’m on a dental procedure, can’t help
Sencer
views.py from django.shortcuts import render, redirect from django.views.generic import TemplateView from django.contrib.auth import authenticate, login, logout from django.contrib.auth.decorators import login_required from .forms import LaporanForm from .models import laporan_umum # Create your views here. def index (request): context = { 'page_title' : 'Selamat Datang | PLN', 'heading' : 'Silahkan Login', } if request.method == "POST": username_login = request.POST['username'] password_login = request.POST['password'] user = authenticate(request, username=username_login, password=password_login) if user is not None: login(request, user) return redirect('laporan:create') else: return redirect('index') return render(request, 'sur_teknik/index.html', context) def create(request): laporan_form = LaporanForm() if request.method == 'POST': laporan_umum.objects.create( ulp = request.POST.get('ulp'), latitude = request.POST.get('latitude'), longtitude = request.POST.get('longtitude'), nama_surveyor = request.POST.get('nama_surveyor'), feder = request.POST.get('feder'), section = request.POST.get('section'), jenis_temuan = request.POST.get('jenis_temuan'), pekerjaan = request.POST.get('pekerjaan'), vol_kerja = request.POST.get('vol_kerja'), satuan_kerja = request.POST.get('satuan_kerja'), detail_kerja = request.POST.get('detail_kerja'), alamat = request.POST.get('alamat'), material = request.POST.get('material'), vol_material = request.POST.get('vol_material'), satuan_material = request.POST.get('satuan_material'), urgensi = request.POST.get('urgensi'), pemadaman = request.POST.get('pemadaman'), tim_pemelihara = request.POST.get('tim_pemelihara'), foto_sebelum = request.POST.get('foto_sebelum'), ) return redirect('laporan:lihat') context = { 'page_title':'Selamat Datang | PLN', 'heading' : 'Masukkan Laporan Anda', 'post_form' : laporan_form, } return render(request,'sur_teknik/create.html',context) def logoutView(request): context = { 'page_title' : 'Selamat Datang | PLN', 'heading' : 'Terima Kasih Atas Laporan Anda', } if request.method == "POST": if request.POST["logout"] == "Submit": logout(request) return redirect('index') return render(request, 'sur_teknik/logout.html', context)
Your problem is in create function. the line "pekerjaan = request.POST.get('pekerjaan')," is setting integer id of the foreign key to "pekerjaan" field instead of "pekerjaan" object. Because form can not send object but object.id you have to do something like this: pekerjaan = pekerjaan.objects.get(id=int(request.POST.get('pekerjaan')))
Sencer
Sari And also your form method usage is wrong. You have to read djangodocs to enhance you model.forms approach.
Muhammed Enes
can i pagination in a specific div?
venkatesh
I have mysql database with 200+ tables, is there any way to generate models in django without losing my data, and what is the best approch to generate either each tabe have each model or entair db have one model please suggest me.
Sencer
Is there a way to visual mapping solution for django models with both way of relations?
Sencer
I need to see the forward and reverse relations of a model
Sencer
Especially reverse relations I needed.
Sencer
Those are the hard to find/reveal ones.
Ansab
Iam using danted server with openvpn to remove block from etisalat.... But still blocking my vpn........ Anyone here to know how to enable voip from UAE....... For devoleping an app....... I just need snippet
Avinash
Any oop expert.?
Doragonsureiyā
Any oop expert.?
Please don't ask meta questions like: "Any user of $x here?" "Anyone used technology $y?" "Hello I need help on $z" Just ask about your problem directly! With 45k+ people the probability that someone will help is pretty high. Also please read: http://catb.org/~esr/faqs/smart-questions.html
cj
can i pagination in a specific div?
yes, but you have to do it using JS
Muhammed Enes
yes, but you have to do it using JS
How can i do it? Can u give me an example or can u help
cj
How can i do it? Can u give me an example or can u help
I use a library called datatable to do that task, look up for it
Anonymous
Pull out India’s states names from this webpage or any where on the internet. - You can use Beautiful Soup or Selenium or Scrapy to do web scraping or any library you want to use. - Extract lat,lon coordinates for those. - You can use Google Maps API. - If you have a better way , go for it. Plz help me.. Anyone
R
can someone ‘splain to me how I get values from my python program to appear in the html page… I know you use {{data}} where ‘data’ is the thing I want to show. I just don’t understand how the {{}} is connected to a python file.
raven
yeah 😅
Mirco
😁😁
Anders (izzno / gooood) 🇳🇴
It's amazing how many people dont follow a single tutorial and expect to get core concepts by "the force"...
Anders (izzno / gooood) 🇳🇴
I dont mean to be rude, but the core value of any programmer should be to do the intro tutorial. If that does not explain the core concepts of the thing you want to learn, it's not worth learning.
Anders (izzno / gooood) 🇳🇴
Django has one of the most thorough introduction tutorials I've seen. Personally I liked Mozilla's take on the tutorial better but still, it shows you everything you need to get going. The only "negative" thing I can think of in regards to Django's documentation is that it assummes you know advanced Python concepts. That might be a bad thing or not depending on the target audience for the framework...
Денис
can someone ‘splain to me how I get values from my python program to appear in the html page… I know you use {{data}} where ‘data’ is the thing I want to show. I just don’t understand how the {{}} is connected to a python file.
Shortly: Django processes templates line by line, meets some name in {{ }} and takes its value from the context. View methods (or classes) are what provides the context. That’s all from me. Go get some additional info in the docs. And learn Python if not yet.
R
it's jinja templating your django do the processing to your html * render() * and sends the HttpResponse('whole html') back as response
Ok, so when i call render() how does the data end up in those braces. Perhaps learning more jinja should help
John
Hi, Denis, nice to see you
John
👍
John
I am from China
John
How about you, Denis?
Mike
How to name an app for an root and app for profile ? 1. for admin(dashboard) python manage.py startapp ....?? 2. for profile python manage.py startapp ...??
Mike
From chine? nice
Денис
How about you, Denis?
According to the rules, I should ignore offtopic. And I’ll do this, yet with respect
John
According to the rules, I should ignore offtopic. And I’ll do this, yet with respect
Oh, really, thanks for your kindness. Acutually, I am new here so I really don't know what to do. I am also an software dev.
Anders (izzno / gooood) 🇳🇴
Ok, so when i call render() how does the data end up in those braces. Perhaps learning more jinja should help
You pass that data as an object to render. Which basically is a function that "renders" that data you just sendt accessing it with special syntax like {{}}. Jinja "is" a language just like Python (Not exactly, but close enogh).
Денис
How to name an app for an root and app for profile ? 1. for admin(dashboard) python manage.py startapp ....?? 2. for profile python manage.py startapp ...??
App name does matter only for you to recognize the app in your project structure and also import it where necessary
Mike
App name does matter only for you to recognize the app in your project structure and also import it where necessary
I cannot name python manage.py startapp profile CommandError: 'profile' conflicts with the name of an existing Python module and cannot be used as an app name. Please try another name.
Денис
I called it 'myprofile' :)
In popular django tutorials there's usually something like "accounts"
Mike
In popular django tutorials there's usually something like "accounts"
but I have already it in my urls.py path('accounts/', include('django.contrib.auth.urls'))
Mike
oops, I got it
Mike
I said bullshit
Денис
Ghorz
Ive spent the whole year learning python. I watched net ninjas excellent tutorials. I was specifically asking how i sent the data to fill those braces. Thanks
Context data. Your data in a dict {} is passed by the django processor to the template and injected where ever {{}} is found with the name, note that template code errors are hard to spot.
坂田銀時
Is doing default='' same as blank=True in models.CharField
坂田銀時
Like is there going to be any issue if someone does default='', other than it being redundant?